From c4e266b87f39d521ff1002fefa9df809c6b9bd61 Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Tue, 30 Aug 2011 15:40:27 -0400 Subject: Added Session driver with native PHP sessions and original-flavor CI cookie sessions --- system/core/Loader.php | 11 +- system/libraries/Driver.php | 42 +- system/libraries/Session.php | 776 --------------------- system/libraries/Session/Session.php | 601 ++++++++++++++++ .../libraries/Session/drivers/Session_cookie.php | 583 ++++++++++++++++ .../libraries/Session/drivers/Session_native.php | 190 +++++ 6 files changed, 1414 insertions(+), 789 deletions(-) delete mode 100644 system/libraries/Session.php create mode 100755 system/libraries/Session/Session.php create mode 100755 system/libraries/Session/drivers/Session_cookie.php create mode 100755 system/libraries/Session/drivers/Session_native.php diff --git a/system/core/Loader.php b/system/core/Loader.php index de0fc06d2..51e6b82ca 100755 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1174,6 +1174,15 @@ class CI_Loader { } } + // Autoload drivers + if (isset($autoload['drivers'])) + { + foreach ($autoload['drivers'] as $item) + { + $this->driver($item); + } + } + // Autoload models if (isset($autoload['model'])) { @@ -1240,4 +1249,4 @@ class CI_Loader { } /* End of file Loader.php */ -/* Location: ./system/core/Loader.php */ \ No newline at end of file +/* Location: ./system/core/Loader.php */ diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 9881c1eec..e958fc67f 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -30,11 +30,32 @@ class CI_Driver_Library { protected $valid_drivers = array(); - protected static $lib_name; - - // The first time a child is used it won't exist, so we instantiate it - // subsequents calls will go straight to the proper child. - function __get($child) + protected $lib_name; + + /** + * Get magic method + * + * The first time a child is used it won't exist, so we instantiate it + * subsequents calls will go straight to the proper child. + * + * @param string Child class name + * @return object Child class + */ + public function __get($child) + { + // Try to load the driver + return load_driver($child); + } + + /** + * Load driver + * + * Separate load_driver call to support explicit driver load by library or user + * + * @param string Child class name + * @return object Child class + */ + public function load_driver($child) { if ( ! isset($this->lib_name)) { @@ -64,7 +85,7 @@ class CI_Driver_Library { if (file_exists($filepath)) { include_once $filepath; - break; + break 2; } } } @@ -84,12 +105,9 @@ class CI_Driver_Library { } // The requested driver isn't valid! - log_message('error', "Invalid driver requested: ".$child_class); - show_error("Invalid driver requested: ".$child_class); + log_message('error', 'Invalid driver requested: '.$child_class); + show_error('Invalid driver requested: '.$child_class); } - - // -------------------------------------------------------------------- - } // END CI_Driver_Library CLASS @@ -226,4 +244,4 @@ class CI_Driver { // END CI_Driver CLASS /* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ \ No newline at end of file +/* Location: ./system/libraries/Driver.php */ diff --git a/system/libraries/Session.php b/system/libraries/Session.php deleted file mode 100644 index 2c8a80163..000000000 --- a/system/libraries/Session.php +++ /dev/null @@ -1,776 +0,0 @@ -CI =& get_instance(); - - // Set all the session preferences, which can either be set - // manually via the $params array above or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) - { - $this->$key = (isset($params[$key])) ? $params[$key] : $this->CI->config->item($key); - } - - if ($this->encryption_key == '') - { - show_error('In order to use the Session class you are required to set an encryption key in your config file.'); - } - - // Load the string helper so we can use the strip_slashes() function - $this->CI->load->helper('string'); - - // Do we need encryption? If so, load the encryption class - if ($this->sess_encrypt_cookie == TRUE) - { - $this->CI->load->library('encrypt'); - } - - // Are we using a database? If so, load it - if ($this->sess_use_database === TRUE AND $this->sess_table_name != '') - { - $this->CI->load->database(); - } - - // Set the "now" time. Can either be GMT or server time, based on the - // config prefs. We use this to set the "last activity" time - $this->now = $this->_get_time(); - - // Set the session length. If the session expiration is - // set to zero we'll set the expiration two years from now. - if ($this->sess_expiration == 0) - { - $this->sess_expiration = (60*60*24*365*2); - } - - // Set the cookie name - $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; - - // Run the Session routine. If a session doesn't exist we'll - // create a new one. If it does, we'll update it. - if ( ! $this->sess_read()) - { - $this->sess_create(); - } - else - { - $this->sess_update(); - } - - // Delete 'old' flashdata (from last request) - $this->_flashdata_sweep(); - - // Mark all new flashdata as old (data will be deleted before next request) - $this->_flashdata_mark(); - - // Delete expired sessions if necessary - $this->_sess_gc(); - - log_message('debug', "Session routines successfully run"); - } - - // -------------------------------------------------------------------- - - /** - * Fetch the current session data if it exists - * - * @access public - * @return bool - */ - function sess_read() - { - // Fetch the cookie - $session = $this->CI->input->cookie($this->sess_cookie_name); - - // No cookie? Goodbye cruel world!... - if ($session === FALSE) - { - log_message('debug', 'A session cookie was not found.'); - return FALSE; - } - - // Decrypt the cookie data - if ($this->sess_encrypt_cookie == TRUE) - { - $session = $this->CI->encrypt->decode($session); - } - else - { - // encryption was not used, so we need to check the md5 hash - $hash = substr($session, strlen($session)-32); // get last 32 chars - $session = substr($session, 0, strlen($session)-32); - - // Does the md5 hash match? This is to prevent manipulation of session data in userspace - if ($hash !== md5($session.$this->encryption_key)) - { - log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); - $this->sess_destroy(); - return FALSE; - } - } - - // Unserialize the session array - $session = $this->_unserialize($session); - - // Is the session data we unserialized an array with the correct format? - if ( ! is_array($session) OR ! isset($session['session_id']) OR ! isset($session['ip_address']) OR ! isset($session['user_agent']) OR ! isset($session['last_activity'])) - { - $this->sess_destroy(); - return FALSE; - } - - // Is the session current? - if (($session['last_activity'] + $this->sess_expiration) < $this->now) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the IP Match? - if ($this->sess_match_ip == TRUE AND $session['ip_address'] != $this->CI->input->ip_address()) - { - $this->sess_destroy(); - return FALSE; - } - - // Does the User Agent Match? - if ($this->sess_match_useragent == TRUE AND trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 120))) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there a corresponding session in the DB? - if ($this->sess_use_database === TRUE) - { - $this->CI->db->where('session_id', $session['session_id']); - - if ($this->sess_match_ip == TRUE) - { - $this->CI->db->where('ip_address', $session['ip_address']); - } - - if ($this->sess_match_useragent == TRUE) - { - $this->CI->db->where('user_agent', $session['user_agent']); - } - - $query = $this->CI->db->get($this->sess_table_name); - - // No result? Kill it! - if ($query->num_rows() == 0) - { - $this->sess_destroy(); - return FALSE; - } - - // Is there custom data? If so, add it to the main session array - $row = $query->row(); - if (isset($row->user_data) AND $row->user_data != '') - { - $custom_data = $this->_unserialize($row->user_data); - - if (is_array($custom_data)) - { - foreach ($custom_data as $key => $val) - { - $session[$key] = $val; - } - } - } - } - - // Session is valid! - $this->userdata = $session; - unset($session); - - return TRUE; - } - - // -------------------------------------------------------------------- - - /** - * Write the session data - * - * @access public - * @return void - */ - function sess_write() - { - // Are we saving custom data to the DB? If not, all we do is update the cookie - if ($this->sess_use_database === FALSE) - { - $this->_set_cookie(); - return; - } - - // set the custom userdata, the session data we will set in a second - $custom_userdata = $this->userdata; - $cookie_userdata = array(); - - // Before continuing, we need to determine if there is any custom data to deal with. - // Let's determine this by removing the default indexes to see if there's anything left in the array - // and set the session data while we're at it - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) - { - unset($custom_userdata[$val]); - $cookie_userdata[$val] = $this->userdata[$val]; - } - - // Did we find any custom data? If not, we turn the empty array into a string - // since there's no reason to serialize and store an empty array in the DB - if (count($custom_userdata) === 0) - { - $custom_userdata = ''; - } - else - { - // Serialize the custom data array so we can store it - $custom_userdata = $this->_serialize($custom_userdata); - } - - // Run the update query - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->update($this->sess_table_name, array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); - - // Write the cookie. Notice that we manually pass the cookie data array to the - // _set_cookie() function. Normally that function will store $this->userdata, but - // in this case that array contains custom data, which we do not want in the cookie. - $this->_set_cookie($cookie_userdata); - } - - // -------------------------------------------------------------------- - - /** - * Create a new session - * - * @access public - * @return void - */ - function sess_create() - { - $sessid = ''; - while (strlen($sessid) < 32) - { - $sessid .= mt_rand(0, mt_getrandmax()); - } - - // To make the session ID even more secure we'll combine it with the user's IP - $sessid .= $this->CI->input->ip_address(); - - $this->userdata = array( - 'session_id' => md5(uniqid($sessid, TRUE)), - 'ip_address' => $this->CI->input->ip_address(), - 'user_agent' => substr($this->CI->input->user_agent(), 0, 120), - 'last_activity' => $this->now - ); - - - // Save the data to the DB if needed - if ($this->sess_use_database === TRUE) - { - $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata)); - } - - // Write the cookie - $this->_set_cookie(); - } - - // -------------------------------------------------------------------- - - /** - * Update an existing session - * - * @access public - * @return void - */ - function sess_update() - { - // We only update the session every five minutes by default - if (($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) - { - return; - } - - // Save the old session id so we know which record to - // update in the database if we need it - $old_sessid = $this->userdata['session_id']; - $new_sessid = ''; - while (strlen($new_sessid) < 32) - { - $new_sessid .= mt_rand(0, mt_getrandmax()); - } - - // To make the session ID even more secure we'll combine it with the user's IP - $new_sessid .= $this->CI->input->ip_address(); - - // Turn it into a hash - $new_sessid = md5(uniqid($new_sessid, TRUE)); - - // Update the session data in the session data array - $this->userdata['session_id'] = $new_sessid; - $this->userdata['last_activity'] = $this->now; - - // _set_cookie() will handle this for us if we aren't using database sessions - // by pushing all userdata to the cookie. - $cookie_data = NULL; - - // Update the session ID and last_activity field in the DB if needed - if ($this->sess_use_database === TRUE) - { - // set cookie explicitly to only have our session data - $cookie_data = array(); - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) - { - $cookie_data[$val] = $this->userdata[$val]; - } - - $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); - } - - // Write the cookie - $this->_set_cookie($cookie_data); - } - - // -------------------------------------------------------------------- - - /** - * Destroy the current session - * - * @access public - * @return void - */ - function sess_destroy() - { - // Kill the session DB row - if ($this->sess_use_database === TRUE AND isset($this->userdata['session_id'])) - { - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->delete($this->sess_table_name); - } - - // Kill the cookie - setcookie( - $this->sess_cookie_name, - addslashes(serialize(array())), - ($this->now - 31500000), - $this->cookie_path, - $this->cookie_domain, - 0 - ); - } - - // -------------------------------------------------------------------- - - /** - * Fetch a specific item from the session array - * - * @access public - * @param string - * @return string - */ - function userdata($item) - { - return ( ! isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; - } - - // -------------------------------------------------------------------- - - /** - * Fetch all session data - * - * @access public - * @return array - */ - function all_userdata() - { - return $this->userdata; - } - - // -------------------------------------------------------------------- - - /** - * Add or change data in the "userdata" array - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_userdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $this->userdata[$key] = $val; - } - } - - $this->sess_write(); - } - - // -------------------------------------------------------------------- - - /** - * Delete a session variable from the "userdata" array - * - * @access array - * @return void - */ - function unset_userdata($newdata = array()) - { - if (is_string($newdata)) - { - $newdata = array($newdata => ''); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - unset($this->userdata[$key]); - } - } - - $this->sess_write(); - } - - // ------------------------------------------------------------------------ - - /** - * Add or change flashdata, only available - * until the next request - * - * @access public - * @param mixed - * @param string - * @return void - */ - function set_flashdata($newdata = array(), $newval = '') - { - if (is_string($newdata)) - { - $newdata = array($newdata => $newval); - } - - if (count($newdata) > 0) - { - foreach ($newdata as $key => $val) - { - $flashdata_key = $this->flashdata_key.':new:'.$key; - $this->set_userdata($flashdata_key, $val); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Keeps existing flashdata available to next request. - * - * @access public - * @param string - * @return void - */ - function keep_flashdata($key) - { - // 'old' flashdata gets removed. Here we mark all - // flashdata as 'new' to preserve it from _flashdata_sweep() - // Note the function will return FALSE if the $key - // provided cannot be found - $old_flashdata_key = $this->flashdata_key.':old:'.$key; - $value = $this->userdata($old_flashdata_key); - - $new_flashdata_key = $this->flashdata_key.':new:'.$key; - $this->set_userdata($new_flashdata_key, $value); - } - - // ------------------------------------------------------------------------ - - /** - * Fetch a specific flashdata item from the session array - * - * @access public - * @param string - * @return string - */ - function flashdata($key) - { - $flashdata_key = $this->flashdata_key.':old:'.$key; - return $this->userdata($flashdata_key); - } - - // ------------------------------------------------------------------------ - - /** - * Identifies flashdata as 'old' for removal - * when _flashdata_sweep() runs. - * - * @access private - * @return void - */ - function _flashdata_mark() - { - $userdata = $this->all_userdata(); - foreach ($userdata as $name => $value) - { - $parts = explode(':new:', $name); - if (is_array($parts) && count($parts) === 2) - { - $new_name = $this->flashdata_key.':old:'.$parts[1]; - $this->set_userdata($new_name, $value); - $this->unset_userdata($name); - } - } - } - - // ------------------------------------------------------------------------ - - /** - * Removes all flashdata marked as 'old' - * - * @access private - * @return void - */ - - function _flashdata_sweep() - { - $userdata = $this->all_userdata(); - foreach ($userdata as $key => $value) - { - if (strpos($key, ':old:')) - { - $this->unset_userdata($key); - } - } - - } - - // -------------------------------------------------------------------- - - /** - * Get the "now" time - * - * @access private - * @return string - */ - function _get_time() - { - if (strtolower($this->time_reference) == 'gmt') - { - $now = time(); - $time = mktime(gmdate("H", $now), gmdate("i", $now), gmdate("s", $now), gmdate("m", $now), gmdate("d", $now), gmdate("Y", $now)); - } - else - { - $time = time(); - } - - return $time; - } - - // -------------------------------------------------------------------- - - /** - * Write the session cookie - * - * @access public - * @return void - */ - function _set_cookie($cookie_data = NULL) - { - if (is_null($cookie_data)) - { - $cookie_data = $this->userdata; - } - - // Serialize the userdata for the cookie - $cookie_data = $this->_serialize($cookie_data); - - if ($this->sess_encrypt_cookie == TRUE) - { - $cookie_data = $this->CI->encrypt->encode($cookie_data); - } - else - { - // if encryption is not used, we provide an md5 hash to prevent userside tampering - $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); - } - - $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); - - // Set the cookie - setcookie( - $this->sess_cookie_name, - $cookie_data, - $expire, - $this->cookie_path, - $this->cookie_domain, - $this->cookie_secure - ); - } - - // -------------------------------------------------------------------- - - /** - * Serialize an array - * - * This function first converts any slashes found in the array to a temporary - * marker, so when it gets unserialized the slashes will be preserved - * - * @access private - * @param array - * @return string - */ - function _serialize($data) - { - if (is_array($data)) - { - foreach ($data as $key => $val) - { - if (is_string($val)) - { - $data[$key] = str_replace('\\', '{{slash}}', $val); - } - } - } - else - { - if (is_string($data)) - { - $data = str_replace('\\', '{{slash}}', $data); - } - } - - return serialize($data); - } - - // -------------------------------------------------------------------- - - /** - * Unserialize - * - * This function unserializes a data string, then converts any - * temporary slash markers back to actual slashes - * - * @access private - * @param array - * @return string - */ - function _unserialize($data) - { - $data = @unserialize(strip_slashes($data)); - - if (is_array($data)) - { - foreach ($data as $key => $val) - { - if (is_string($val)) - { - $data[$key] = str_replace('{{slash}}', '\\', $val); - } - } - - return $data; - } - - return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data; - } - - // -------------------------------------------------------------------- - - /** - * Garbage collection - * - * This deletes expired session rows from database - * if the probability percentage is met - * - * @access public - * @return void - */ - function _sess_gc() - { - if ($this->sess_use_database != TRUE) - { - return; - } - - srand(time()); - if ((rand() % 100) < $this->gc_probability) - { - $expire = $this->now - $this->sess_expiration; - - $this->CI->db->where("last_activity < {$expire}"); - $this->CI->db->delete($this->sess_table_name); - - log_message('debug', 'Session garbage collection performed.'); - } - } - - -} -// END Session Class - -/* End of file Session.php */ -/* Location: ./system/libraries/Session.php */ \ No newline at end of file diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php new file mode 100755 index 000000000..7aaf706a1 --- /dev/null +++ b/system/libraries/Session/Session.php @@ -0,0 +1,601 @@ +session or $this->session). + * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing. + * The Session library class keeps track of the most recently loaded driver as "current" to call for driver methods. + * Ideally, one driver is loaded and all calls go directly through the main library interface. However, any methods + * called through the specific driver will switch the "current" driver to itself before invoking the library method + * (which will then call back into the driver for low-level operations). So, alternation between two drivers can be + * achieved by specifying which driver to use for each call (e.g.: $this->session->native->set_userdata('foo', 'bar'); + * $this->session->cookie->userdata('foo'); $this->session->native->unset_userdata('foo');). Notice in the previous + * example that the _native_ userdata value 'foo' would be set to 'bar', which would NOT be returned by the call for + * the _cookie_ userdata 'foo', nor would the _cookie_ value be unset by the call to unset the _native_ 'foo' value. + * + * @package CodeIgniter + * @subpackage Libraries + * @category Sessions + * @author Darren Hill (DChill) + * @link http://codeigniter.com/user_guide/libraries/sessions.html + */ +final class Session extends CI_Driver_Library { + public $params = array(); + private $current = null; + private $userdata = array(); + + const FLASHDATA_KEY = 'flash'; + const FLASHDATA_NEW = ':new:'; + const FLASHDATA_OLD = ':old:'; + const FLASHDATA_EXP = ':exp:'; + const EXPIRATION_KEY = '__expirations'; + const TEMP_EXP_DEF = 300; + + /** + * Session constructor + * + * The constructor loads the configured driver ('sess_driver' in config.php or as a parameter), running + * routines in its constructor, and manages flashdata aging. + * + * @param array Configuration parameters + */ + public function __construct(array $params = array()) + { + log_message('debug', 'Session Class Initialized'); + + // Get valid drivers list + $CI =& get_instance(); + $this->valid_drivers = array('Session_Native', 'Session_Cookie'); + $key = 'sess_valid_drivers'; + $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); + if ($drivers) + { + if (!is_array($drivers)) $drivers = array($drivers); + + // Add driver names to valid list + foreach ($drivers as $driver) + { + if (!in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers))) + { + $this->valid_drivers[] = $driver; + } + } + } + + // Get driver to load + $key = 'sess_driver'; + $driver = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); + if (!$driver) $driver = 'Native'; + if (!in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers))) + { + $this->valid_drivers[] = 'Session_'.$driver; + } + + // Save a copy of parameters in case drivers need access + $this->params = $params; + + // Load driver and get array reference + $this->load_driver($driver); + $this->userdata =& $this->current->get_userdata(); + + // Delete 'old' flashdata (from last request) + $this->_flashdata_sweep(); + + // Mark all new flashdata as old (data will be deleted before next request) + $this->_flashdata_mark(); + + // Delete expired tempdata + $this->_tempdata_sweep(); + + log_message('debug', 'Session routines successfully run'); + } + + /** + * Loads session storage driver + * + * @param string Driver classname + * @return object Loaded driver object + */ + public function load_driver($driver) + { + // Save reference to most recently loaded driver as library default + $this->current = parent::load_driver($driver); + return $this->current; + } + + /** + * Select default session storage driver + * + * @param string Driver classname + * @return void + */ + public function select_driver($driver) + { + // Validate driver name + $lowername = strtolower($driver); + if (in_array($lowername, array_map('strtolower', $this->valid_drivers))) + { + // See if regular or lowercase variant is loaded + if (class_exists($driver)) + { + $this->current = $this->$driver; + } + else if (class_exists($lowername)) + { + $this->current = $this->$lowername; + } + else + { + $this->load_driver($driver); + } + } + } + + /** + * Destroy the current session + * + * @return void + */ + public function sess_destroy() + { + // Just call destroy on driver + $this->current->sess_destroy(); + } + + /** + * Regenerate the current session + * + * @param boolean Destroy session data flag (default: false) + * @return void + */ + public function sess_regenerate($destroy = false) + { + // Just call regenerate on driver + $this->current->sess_regenerate($destroy); + } + + /** + * Fetch a specific item from the session array + * + * @param string Item key + * @return string Item value + */ + public function userdata($item) + { + // Return value or FALSE if not found + return (!isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + } + + /** + * Fetch all session data + * + * @return array User data array + */ + public function all_userdata() + { + // Return entire array + return (!isset($this->userdata)) ? FALSE : $this->userdata; + } + + /** + * Add or change data in the "userdata" array + * + * @param mixed Item name or array of items + * @param string Item value or empty string + * @return void + */ + public function set_userdata($newdata = array(), $newval = '') + { + // Wrap params as array if singular + if (is_string($newdata)) + { + $newdata = array($newdata => $newval); + } + + // Set each name/value pair + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $this->userdata[$key] = $val; + } + } + + // Tell driver data changed + $this->current->sess_save(); + } + + /** + * Delete a session variable from the "userdata" array + * + * @param mixed Item name or array of item names + * @return void + */ + public function unset_userdata($newdata = array()) + { + // Wrap single name as array + if (is_string($newdata)) + { + $newdata = array($newdata => ''); + } + + // Unset each item name + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + unset($this->userdata[$key]); + } + } + + // Tell driver data changed + $this->current->sess_save(); + } + + /** + * Determine if an item exists + * + * @param string Item name + * @return boolean + */ + public function has_userdata($item) + { + // Check for item name + return isset($this->userdata[$item]); + } + + /** + * Add or change flashdata, only available until the next request + * + * @param mixed Item name or array of items + * @param string Item value or empty string + * @return void + */ + public function set_flashdata($newdata = array(), $newval = '') + { + // Wrap item as array if singular + if (is_string($newdata)) + { + $newdata = array($newdata => $newval); + } + + // Prepend each key name and set value + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; + $this->set_userdata($flashdata_key, $val); + } + } + } + + /** + * Keeps existing flashdata available to next request. + * + * @param string Item key + * @return void + */ + public function keep_flashdata($key) + { + // 'old' flashdata gets removed. Here we mark all + // flashdata as 'new' to preserve it from _flashdata_sweep() + $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; + $value = $this->userdata($old_flashdata_key); + + $new_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_NEW.$key; + $this->set_userdata($new_flashdata_key, $value); + } + + /** + * Fetch a specific flashdata item from the session array + * + * @param string Item key + * @return string + */ + public function flashdata($key) + { + // Prepend key and retrieve value + $flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; + return $this->userdata($flashdata_key); + } + + /** + * Add or change tempdata, only available + * until expiration + * + * @param mixed Item name or array of items + * @param string Item value or empty string + * @param int Item lifetime in seconds or 0 for default + * @return void + */ + public function set_tempdata($newdata = array(), $newval = '', $expire = 0) + { + // Set expiration time + $expire = time() + ($expire ? $expire : self::TEMP_EXP_DEF); + + // Wrap item as array if singular + if (is_string($newdata)) + { + $newdata = array($newdata => $newval); + } + + // Get or create expiration list + $expirations = $this->userdata(self::EXPIRATION_KEY); + if (!$expirations) + { + $expirations = array(); + } + + // Prepend each key name and set value + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; + $expirations[$tempdata_key] = $expire; + $this->set_userdata($tempdata_key, $val); + } + } + + // Update expiration list + $this->set_userdata(self::EXPIRATION_KEY, $expirations); + } + + /** + * Delete a temporary session variable from the "userdata" array + * + * @param mixed Item name or array of item names + * @return void + */ + public function unset_tempdata($newdata = array()) + { + // Get expirations list + $expirations = $this->userdata(self::EXPIRATION_KEY); + if (!$expirations || !count($expirations)) + { + // Nothing to do + return; + } + + // Wrap single name as array + if (is_string($newdata)) + { + $newdata = array($newdata => ''); + } + + // Prepend each item name and unset + if (count($newdata) > 0) + { + foreach ($newdata as $key => $val) + { + $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; + unset($expirations[$tempdata_key]); + $this->unset_userdata($tempdata_key); + } + } + + // Update expiration list + $this->set_userdata(self::EXPIRATION_KEY, $expirations); + } + + /** + * Fetch a specific tempdata item from the session array + * + * @param string Item key + * @return string + */ + public function tempdata($key) + { + // Prepend key and return value + $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; + return $this->userdata($tempdata_key); + } + + /** + * Identifies flashdata as 'old' for removal + * when _flashdata_sweep() runs. + * + * @access private + * @return void + */ + private function _flashdata_mark() + { + $userdata = $this->all_userdata(); + foreach ($userdata as $name => $value) + { + $parts = explode(self::FLASHDATA_NEW, $name); + if (is_array($parts) && count($parts) === 2) + { + $new_name = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$parts[1]; + $this->set_userdata($new_name, $value); + $this->unset_userdata($name); + } + } + } + + /** + * Removes all flashdata marked as 'old' + * + * @access private + * @return void + */ + private function _flashdata_sweep() + { + $userdata = $this->all_userdata(); + foreach ($userdata as $key => $value) + { + if (strpos($key, self::FLASHDATA_OLD)) + { + $this->unset_userdata($key); + } + } + } + + /** + * Removes all expired tempdata + * + * @access private + * @return void + */ + private function _tempdata_sweep() + { + // Get expirations list + $expirations = $this->userdata(self::EXPIRATION_KEY); + if (!$expirations || !count($expirations)) + { + // Nothing to do + return; + } + + // Unset expired elements + $now = time(); + $userdata = $this->all_userdata(); + foreach ($userdata as $key => $value) + { + if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now) + { + unset($expirations[$key]); + $this->unset_userdata($key); + } + } + + // Update expiration list + $this->set_userdata(self::EXPIRATION_KEY, $expirations); + } +} +// END Session Class + + +/** + * SessionDriver Class + * + * Extend this class to make a new Session driver. + * A Session driver basically manages an array of name/value pairs with some sort of storage mechanism. + * To make a new driver, derive from (extend) SessionDriver. Overload the initialize method and read or create + * session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler + * to remove deleted data (sess_destroy), and an access handler to expose the data (get_userdata). + * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the application + * directory, the system directory, or any path you add with $CI->load->add_package_path(). + * Your driver must be named Session_, where is capitalized, and your filename must be Session_.EXT, + * preferably also capitalized. (e.g.: Session_Foo in libraries/Session/drivers/Session_Foo.php) + * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the Session + * object. (e.g.: $config['sess_driver'] = 'foo'; OR $CI->load->driver('session', array('sess_driver' => 'foo')); ) + * Already provided are the Native driver, which manages the native PHP $_SESSION array, and + * the Cookie driver, which manages the data in a browser cookie, with optional extra storage in a database table. + * + * @package CodeIgniter + * @subpackage Libraries + * @category Sessions + * @author Darren Hill (DChill) + */ +abstract class SessionDriver extends CI_Driver { + /** + * Decorate + * + * Decorates the child with the parent driver lib's methods and properties + * + * @param object Parent library object + * @return void + */ + public function decorate($parent) + { + // Call base class decorate first + parent::decorate($parent); + + // Call initialize method now that driver has access to $this->parent + $this->initialize(); + } + + /** + * __call magic method + * + * Handles access to the parent driver library's methods + * + * @param string Library method name + * @param array Method arguments (default: none) + * @return mixed + */ + public function __call($method, $args = array()) + { + // Make sure the parent library uses this driver + $this->parent->select_driver(get_class($this)); + return parent::__call($method, $args); + } + + /** + * Initialize driver + * + * @return void + */ + protected function initialize() + { + // Overload this method to implement initialization + } + + /** + * Save the session data + * + * Data in the array has changed - perform any storage synchronization necessary + * The child class MUST implement this abstract method! + * + * @return void + */ + abstract public function sess_save(); + + /** + * Destroy the current session + * + * Clean up storage for this session - it has been terminated + * The child class MUST implement this abstract method! + * + * @return void + */ + abstract public function sess_destroy(); + + /** + * Regenerate the current session + * + * Regenerate the session id + * The child class MUST implement this abstract method! + * + * @param boolean Destroy session data flag (default: false) + * @return void + */ + abstract public function sess_regenerate($destroy = false); + + /** + * Get a reference to user data array + * + * Give array access to the main Session object + * The child class MUST implement this abstract method! + * + * @return array Reference to userdata + */ + abstract public function &get_userdata(); +} +// END SessionDriver Class + + +/* End of file Session.php */ +/* Location: ./system/libraries/Session/Session.php */ +?> diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php new file mode 100755 index 000000000..0982b1e01 --- /dev/null +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -0,0 +1,583 @@ +CI =& get_instance(); + + // Set all the session preferences, which can either be set + // manually via the $params array above or via the config file + foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', + 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', + 'cookie_domain', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) + { + $this->$key = (isset($this->parent->params[$key])) ? $this->parent->params[$key] : $this->CI->config->item($key); + } + + if ($this->encryption_key == '') + { + show_error('In order to use the Cookie Session driver you are required to set an encryption key '. + 'in your config file.'); + } + + // Load the string helper so we can use the strip_slashes() function + $this->CI->load->helper('string'); + + // Do we need encryption? If so, load the encryption class + if ($this->sess_encrypt_cookie == TRUE) + { + $this->CI->load->library('encrypt'); + } + + // Are we using a database? If so, load it + if ($this->sess_use_database === TRUE && $this->sess_table_name != '') + { + $this->CI->load->database(); + } + + // Set the "now" time. Can either be GMT or server time, based on the config prefs. + // We use this to set the "last activity" time + $this->now = $this->_get_time(); + + // Set the session length. If the session expiration is + // set to zero we'll set the expiration two years from now. + if ($this->sess_expiration == 0) + { + $this->sess_expiration = (60*60*24*365*2); + } + + // Set the cookie name + $this->sess_cookie_name = $this->cookie_prefix.$this->sess_cookie_name; + + // Run the Session routine. If a session doesn't exist we'll + // create a new one. If it does, we'll update it. + if ( ! $this->_sess_read()) + { + $this->_sess_create(); + } + else + { + $this->_sess_update(); + } + + // Delete expired sessions if necessary + $this->_sess_gc(); + } + + /** + * Write the session data + * + * @return void + */ + public function sess_save() + { + // Are we saving custom data to the DB? If not, all we do is update the cookie + if ($this->sess_use_database === FALSE) + { + $this->_set_cookie(); + return; + } + + // set the custom userdata, the session data we will set in a second + $custom_userdata = $this->all_userdata(); + $cookie_userdata = array(); + + // Before continuing, we need to determine if there is any custom data to deal with. + // Let's determine this by removing the default indexes to see if there's anything left in the array + // and set the session data while we're at it + foreach (array('session_id','ip_address','user_agent','last_activity') as $val) + { + unset($custom_userdata[$val]); + $cookie_userdata[$val] = $this->userdata($val); + } + + // Did we find any custom data? If not, we turn the empty array into a string + // since there's no reason to serialize and store an empty array in the DB + if (count($custom_userdata) === 0) + { + $custom_userdata = ''; + } + else + { + // Serialize the custom data array so we can store it + $custom_userdata = $this->_serialize($custom_userdata); + } + + // Run the update query + $this->CI->db->where('session_id', $this->userdata('session_id')); + $this->CI->db->update($this->sess_table_name, + array('last_activity' => $this->userdata('last_activity'), 'user_data' => $custom_userdata)); + + // Write the cookie. Notice that we manually pass the cookie data array to the + // _set_cookie() function. Normally that function will store $this->userdata, but + // in this case that array contains custom data, which we do not want in the cookie. + $this->_set_cookie($cookie_userdata); + } + + /** + * Destroy the current session + * + * @return void + */ + public function sess_destroy() + { + // Kill the session DB row + if ($this->sess_use_database === TRUE && $this->has_userdata('session_id')) + { + $this->CI->db->where('session_id', $this->userdata['session_id']); + $this->CI->db->delete($this->sess_table_name); + } + + // Kill the cookie + setcookie($this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000), + $this->cookie_path, $this->cookie_domain, 0); + } + + /** + * Regenerate the current session + * + * Regenerate the session id + * + * @param boolean Destroy session data flag (default: false) + * @return void + */ + public function sess_regenerate($destroy = false) + { + // Check destroy flag + if ($destroy) + { + // Destroy old session and create new one + $this->sess_destroy(); + $this->_sess_create(); + } + else + { + // Just force an update to recreate the id + $this->_sess_update(true); + } + } + + /** + * Get a reference to user data array + * + * @return array - Reference to userdata + */ + public function &get_userdata() + { + // Return reference to array + return $this->userdata; + } + + /** + * Fetch the current session data if it exists + * + * @access private + * @return bool + */ + private function _sess_read() + { + // Fetch the cookie + $session = $this->CI->input->cookie($this->sess_cookie_name); + + // No cookie? Goodbye cruel world!... + if ($session === FALSE) + { + log_message('debug', 'A session cookie was not found.'); + return FALSE; + } + + // Decrypt the cookie data + if ($this->sess_encrypt_cookie == TRUE) + { + $session = $this->CI->encrypt->decode($session); + } + else + { + // encryption was not used, so we need to check the md5 hash + $hash = substr($session, strlen($session)-32); // get last 32 chars + $session = substr($session, 0, strlen($session)-32); + + // Does the md5 hash match? This is to prevent manipulation of session data in userspace + if ($hash !== md5($session.$this->encryption_key)) + { + log_message('error', 'The session cookie data did not match what was expected. '. + 'This could be a possible hacking attempt.'); + $this->sess_destroy(); + return FALSE; + } + } + + // Unserialize the session array + $session = $this->_unserialize($session); + + // Is the session data we unserialized an array with the correct format? + if ( ! is_array($session) || ! isset($session['session_id']) || ! isset($session['ip_address']) || + ! isset($session['user_agent']) || ! isset($session['last_activity'])) + { + $this->sess_destroy(); + return FALSE; + } + + // Is the session current? + if (($session['last_activity'] + $this->sess_expiration) < $this->now()) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the IP Match? + if ($this->sess_match_ip == TRUE && $session['ip_address'] != $this->CI->input->ip_address()) + { + $this->sess_destroy(); + return FALSE; + } + + // Does the User Agent Match? + if ($this->sess_match_useragent == TRUE && + trim($session['user_agent']) != trim(substr($this->CI->input->user_agent(), 0, 50))) + { + $this->sess_destroy(); + return FALSE; + } + + // Is there a corresponding session in the DB? + if ($this->sess_use_database === TRUE) + { + $this->CI->db->where('session_id', $session['session_id']); + + if ($this->sess_match_ip == TRUE) + { + $this->CI->db->where('ip_address', $session['ip_address']); + } + + if ($this->sess_match_useragent == TRUE) + { + $this->CI->db->where('user_agent', $session['user_agent']); + } + + $query = $this->CI->db->get($this->sess_table_name); + + // No result? Kill it! + if ($query->num_rows() == 0) + { + $this->sess_destroy(); + return FALSE; + } + + // Is there custom data? If so, add it to the main session array + $row = $query->row(); + if (isset($row->user_data) && $row->user_data != '') + { + $custom_data = $this->_unserialize($row->user_data); + + if (is_array($custom_data)) + { + foreach ($custom_data as $key => $val) + { + $session[$key] = $val; + } + } + } + } + + // Session is valid! + $this->userdata = $session; + unset($session); + + return TRUE; + } + + /** + * Create a new session + * + * @access private + * @return void + */ + private function _sess_create() + { + $sessid = ''; + while (strlen($sessid) < 32) + { + $sessid .= mt_rand(0, mt_getrandmax()); + } + + // To make the session ID even more secure we'll combine it with the user's IP + $sessid .= $this->CI->input->ip_address(); + + $this->set_userdata('session_id', md5(uniqid($sessid, TRUE))); + $this->set_userdata('ip_address', $this->CI->input->ip_address()); + $this->set_userdata('user_agent', substr($this->CI->input->user_agent(), 0, 50)); + $this->set_userdata('last_activity',$this->now()); + + + // Save the data to the DB if needed + if ($this->sess_use_database === TRUE) + { + $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->all_userdata())); + } + + // Write the cookie + $this->_set_cookie(); + } + + /** + * Update an existing session + * + * @access private + * @param boolean Force update flag (default: false) + * @return void + */ + private function _sess_update($force = false) + { + // We only update the session every five minutes by default (unless forced) + if (!$force && ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now()) + { + return; + } + + // Save the old session id so we know which record to + // update in the database if we need it + $old_sessid = $this->userdata['session_id']; + $new_sessid = ''; + while (strlen($new_sessid) < 32) + { + $new_sessid .= mt_rand(0, mt_getrandmax()); + } + + // To make the session ID even more secure we'll combine it with the user's IP + $new_sessid .= $this->CI->input->ip_address(); + + // Turn it into a hash + $new_sessid = md5(uniqid($new_sessid, TRUE)); + + // Update the session data in the session data array + $this->set_userdata('session_id', $new_sessid); + $this->set_userdata('last_activity', $this->now()); + + // _set_cookie() will handle this for us if we aren't using database sessions + // by pushing all userdata to the cookie. + $cookie_data = NULL; + + // Update the session ID and last_activity field in the DB if needed + if ($this->sess_use_database === TRUE) + { + // set cookie explicitly to only have our session data + $cookie_data = array(); + foreach (array('session_id','ip_address','user_agent','last_activity') as $val) + { + $cookie_data[$val] = $this->userdata[$val]; + } + + $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, + array('last_activity' => $this->now(), 'session_id' => $new_sessid), + array('session_id' => $old_sessid))); + } + + // Write the cookie + $this->_set_cookie($cookie_data); + } + + /** + * Get the "now" time + * + * @access private + * @return int + */ + private function _get_time() + { + if (strtolower($this->time_reference) == 'gmt') + { + $now = time(); + $time = mktime(gmdate('H', $now), gmdate('i', $now), gmdate('s', $now), gmdate('m', $now), + gmdate('d', $now), gmdate('Y', $now)); + } + else + { + $time = time(); + } + + return $time; + } + + /** + * Write the session cookie + * + * @access private + * @param array Cookie name/value pairs + * @return void + */ + private function _set_cookie(array $cookie_data = NULL) + { + if (is_null($cookie_data)) + { + $cookie_data = $this->all_userdata(); + } + + // Serialize the userdata for the cookie + $cookie_data = $this->_serialize($cookie_data); + + if ($this->sess_encrypt_cookie == TRUE) + { + $cookie_data = $this->CI->encrypt->encode($cookie_data); + } + else + { + // if encryption is not used, we provide an md5 hash to prevent userside tampering + $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); + } + + $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); + + // Set the cookie + setcookie($this->sess_cookie_name, $cookie_data, $expire, $this->cookie_path, $this->cookie_domain, 0); + } + + /** + * Serialize an array + * + * This function first converts any slashes found in the array to a temporary + * marker, so when it gets unserialized the slashes will be preserved + * + * @access private + * @param mixed Data to serialize + * @return string + */ + private function _serialize($data) + { + if (is_array($data)) + { + foreach ($data as $key => $val) + { + if (is_string($val)) + { + $data[$key] = str_replace('\\', '{{slash}}', $val); + } + } + } + else + { + if (is_string($data)) + { + $data = str_replace('\\', '{{slash}}', $data); + } + } + + return serialize($data); + } + + /** + * Unserialize + * + * This function unserializes a data string, then converts any + * temporary slash markers back to actual slashes + * + * @access private + * @param string Data to unserialize + * @return mixed + */ + private function _unserialize($data) + { + $data = @unserialize(strip_slashes($data)); + + if (is_array($data)) + { + foreach ($data as $key => $val) + { + if (is_string($val)) + { + $data[$key] = str_replace('{{slash}}', '\\', $val); + } + } + + return $data; + } + + return (is_string($data)) ? str_replace('{{slash}}', '\\', $data) : $data; + } + + /** + * Garbage collection + * + * This deletes expired session rows from database + * if the probability percentage is met + * + * @access private + * @return void + */ + private function _sess_gc() + { + if ($this->sess_use_database != TRUE) + { + return; + } + + srand(time()); + if ((rand() % 100) < self::gc_probability) + { + $expire = $this->now() - $this->sess_expiration; + + $this->CI->db->where('last_activity < '.$expire); + $this->CI->db->delete($this->sess_table_name); + + log_message('debug', 'Session garbage collection performed.'); + } + } +} +// END Session_Cookie Class + +/* End of file Session_cookie.php */ +/* Location: ./system/libraries/Session/Session.php */ +?> diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php new file mode 100755 index 000000000..df588175f --- /dev/null +++ b/system/libraries/Session/drivers/Session_native.php @@ -0,0 +1,190 @@ +parent->params[$key]) ? $this->parent->params[$key] : $CI->config->item($key); + } + + // Set session name, if specified + if ($config['sess_cookie_name']) + { + $name = $config['sess_cookie_name']; + if ($config['cookie_prefix']) + { + // Prepend cookie prefix + $name = $config['cookie_prefix'].$name; + } + session_name($name); + } + + // Set expiration, path, and domain + $expire = 7200; + $path = '/'; + $domain = ''; + if ($config['sess_expiration'] !== FALSE) + { + // Default to 2 years if expiration is "0" + $expire = ($config['sess_expiration'] == 0) ? (60*60*24*365*2) : $config['sess_expiration']; + } + if ($config['cookie_path']) + { + // Use specified path + $path = $config['cookie_path']; + } + if ($config['cookie_domain']) + { + // Use specified domain + $domain = $config['cookie_domain']; + } + session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain); + + // Start session + session_start(); + + // Check session expiration, ip, and agent + $now = time(); + $destroy = FALSE; + if (isset($_SESSION['last_activity']) && ($_SESSION['last_activity'] + $expire) < $now) + { + // Expired - destroy + $destroy = TRUE; + } + else if ($config['sess_match_ip'] == TRUE && isset($_SESSION['ip_address']) && + $_SESSION['ip_address'] != $CI->input->ip_address()) + { + // IP doesn't match - destroy + $destroy = TRUE; + } + else if ($config['sess_match_useragent'] == TRUE && isset($_SESSION['user_agent']) && + $_SESSION['user_agent'] != trim(substr($CI->input->user_agent(), 0, 50))) + { + // Agent doesn't match - destroy + $destroy = TRUE; + } + + // Destroy expired or invalid session + if ($destroy) + { + // Clear old session and start new + $this->sess_destroy(); + session_start(); + } + + // Set activity time + $_SESSION['last_activity'] = $now; + + // Set matching values as required + if ($config['sess_match_ip'] == TRUE && !isset($_SESSION['ip_address'])) + { + // Store user IP address + $_SESSION['ip_address'] = $CI->input->ip_address(); + } + if ($config['sess_match_useragent'] == TRUE && !isset($_SESSION['user_agent'])) + { + // Store user agent string + $_SESSION['user_agent'] = trim(substr($CI->input->user_agent(), 0, 50)); + } + } + + /** + * Save the session data + * + * @access public + * @return void + */ + public function sess_save() + { + // Nothing to do - changes to $_SESSION are automatically saved + } + + /** + * Destroy the current session + * + * @access public + * @return void + */ + public function sess_destroy() + { + // Cleanup session + $_SESSION = array(); + $name = session_name(); + if (isset($_COOKIE[$name])) + { + // Clear session cookie + $params = session_get_cookie_params(); + setcookie($name, '', time() - 42000, $params['path'], $params['domain']); + unset($_COOKIE[$name]); + } + session_destroy(); + } + + /** + * Regenerate the current session + * + * Regenerate the session id + * + * @access public + * @param boolean Destroy session data flag (default: false) + * @return void + */ + public function sess_regenerate($destroy = false) + { + // Just regenerate id, passing destroy flag + session_regenerate_id($destroy); + } + + /** + * Get a reference to user data array + * + * @access public + * @return array Reference to userdata + */ + public function &get_userdata() + { + // Just return reference to $_SESSION + return $_SESSION; + } +} +// END Session_Native Class + + +/* End of file Session_native.php */ +/* Location: ./system/libraries/Session/Session.php */ +?> -- cgit v1.2.3-24-g4f1b From 3bd8d1ad9273f12c47d1ce1f59d4140718a02e4f Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Wed, 31 Aug 2011 08:28:16 -0400 Subject: Removed ucfirst on Driver library name --- system/libraries/Driver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index e958fc67f..c3bcc252e 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -66,8 +66,8 @@ class CI_Driver_Library { $child_class = $this->lib_name.'_'.$child; // Remove the CI_ prefix and lowercase - $lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name))); - $driver_name = strtolower(str_replace('CI_', '', $child_class)); + $lib_name = strtolower(preg_replace('/^CI_/', '', $this->lib_name)); + $driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) { -- cgit v1.2.3-24-g4f1b From ca3be1d515a68293b64704a9a8346802702dedaa Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Wed, 31 Aug 2011 08:31:18 -0400 Subject: Whitespace cleanup --- system/core/Loader.php | 8 ++++---- system/libraries/Driver.php | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/system/core/Loader.php b/system/core/Loader.php index 51e6b82ca..edf5853f0 100755 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1177,10 +1177,10 @@ class CI_Loader { // Autoload drivers if (isset($autoload['drivers'])) { - foreach ($autoload['drivers'] as $item) - { - $this->driver($item); - } + foreach ($autoload['drivers'] as $item) + { + $this->driver($item); + } } // Autoload models diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index c3bcc252e..80c0e2812 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -32,29 +32,29 @@ class CI_Driver_Library { protected $valid_drivers = array(); protected $lib_name; - /** - * Get magic method - * + /** + * Get magic method + * * The first time a child is used it won't exist, so we instantiate it * subsequents calls will go straight to the proper child. - * - * @param string Child class name - * @return object Child class - */ + * + * @param string Child class name + * @return object Child class + */ public function __get($child) { - // Try to load the driver + // Try to load the driver return load_driver($child); - } + } - /** - * Load driver - * + /** + * Load driver + * * Separate load_driver call to support explicit driver load by library or user - * - * @param string Child class name - * @return object Child class - */ + * + * @param string Child class name + * @return object Child class + */ public function load_driver($child) { if ( ! isset($this->lib_name)) -- cgit v1.2.3-24-g4f1b From 5073a375951f09b654f6b991df7ca04e1f88d93c Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Wed, 31 Aug 2011 13:54:19 -0400 Subject: Better style guide compliance --- system/libraries/Session/Session.php | 136 ++++++++++----------- .../libraries/Session/drivers/Session_cookie.php | 8 +- .../libraries/Session/drivers/Session_native.php | 8 +- 3 files changed, 76 insertions(+), 76 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 7aaf706a1..dacc249c5 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -15,15 +15,15 @@ /** - * Session Class + * CI_Session Class * * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms. - * By default, the Native PHP session driver will load, but the 'sess_driver' config/param item (see above) can be - * used to specify the 'Cookie' driver, or any other you might create. + * By default, the native PHP session driver will load, but the 'sess_driver' config/param item (see above) can be + * used to specify the 'cookie' driver, or any other you might create. * Once loaded, this driver setup is a drop-in replacement for the former CI_Session library, taking its place as the * 'session' member of the global controller framework (e.g.: $CI->session or $this->session). * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing. - * The Session library class keeps track of the most recently loaded driver as "current" to call for driver methods. + * The CI_Session library class keeps track of the most recently loaded driver as "current" to call for driver methods. * Ideally, one driver is loaded and all calls go directly through the main library interface. However, any methods * called through the specific driver will switch the "current" driver to itself before invoking the library method * (which will then call back into the driver for low-level operations). So, alternation between two drivers can be @@ -35,10 +35,10 @@ * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author Darren Hill (DChill) + * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/sessions.html */ -final class Session extends CI_Driver_Library { +final class CI_Session extends CI_Driver_Library { public $params = array(); private $current = null; private $userdata = array(); @@ -51,20 +51,20 @@ final class Session extends CI_Driver_Library { const TEMP_EXP_DEF = 300; /** - * Session constructor + * CI_Session constructor * * The constructor loads the configured driver ('sess_driver' in config.php or as a parameter), running * routines in its constructor, and manages flashdata aging. * - * @param array Configuration parameters + * @param array Configuration parameters */ public function __construct(array $params = array()) { - log_message('debug', 'Session Class Initialized'); + log_message('debug', 'CI_Session Class Initialized'); // Get valid drivers list $CI =& get_instance(); - $this->valid_drivers = array('Session_Native', 'Session_Cookie'); + $this->valid_drivers = array('CI_Session_native', 'CI_Session_cookie'); $key = 'sess_valid_drivers'; $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); if ($drivers) @@ -84,7 +84,7 @@ final class Session extends CI_Driver_Library { // Get driver to load $key = 'sess_driver'; $driver = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); - if (!$driver) $driver = 'Native'; + if (!$driver) $driver = 'native'; if (!in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers))) { $this->valid_drivers[] = 'Session_'.$driver; @@ -106,14 +106,14 @@ final class Session extends CI_Driver_Library { // Delete expired tempdata $this->_tempdata_sweep(); - log_message('debug', 'Session routines successfully run'); + log_message('debug', 'CI_Session routines successfully run'); } /** * Loads session storage driver * - * @param string Driver classname - * @return object Loaded driver object + * @param string Driver classname + * @return object Loaded driver object */ public function load_driver($driver) { @@ -125,8 +125,8 @@ final class Session extends CI_Driver_Library { /** * Select default session storage driver * - * @param string Driver classname - * @return void + * @param string Driver classname + * @return void */ public function select_driver($driver) { @@ -153,7 +153,7 @@ final class Session extends CI_Driver_Library { /** * Destroy the current session * - * @return void + * @return void */ public function sess_destroy() { @@ -164,8 +164,8 @@ final class Session extends CI_Driver_Library { /** * Regenerate the current session * - * @param boolean Destroy session data flag (default: false) - * @return void + * @param boolean Destroy session data flag (default: false) + * @return void */ public function sess_regenerate($destroy = false) { @@ -176,8 +176,8 @@ final class Session extends CI_Driver_Library { /** * Fetch a specific item from the session array * - * @param string Item key - * @return string Item value + * @param string Item key + * @return string Item value */ public function userdata($item) { @@ -199,9 +199,9 @@ final class Session extends CI_Driver_Library { /** * Add or change data in the "userdata" array * - * @param mixed Item name or array of items - * @param string Item value or empty string - * @return void + * @param mixed Item name or array of items + * @param string Item value or empty string + * @return void */ public function set_userdata($newdata = array(), $newval = '') { @@ -227,8 +227,8 @@ final class Session extends CI_Driver_Library { /** * Delete a session variable from the "userdata" array * - * @param mixed Item name or array of item names - * @return void + * @param mixed Item name or array of item names + * @return void */ public function unset_userdata($newdata = array()) { @@ -254,8 +254,8 @@ final class Session extends CI_Driver_Library { /** * Determine if an item exists * - * @param string Item name - * @return boolean + * @param string Item name + * @return boolean */ public function has_userdata($item) { @@ -266,9 +266,9 @@ final class Session extends CI_Driver_Library { /** * Add or change flashdata, only available until the next request * - * @param mixed Item name or array of items - * @param string Item value or empty string - * @return void + * @param mixed Item name or array of items + * @param string Item value or empty string + * @return void */ public function set_flashdata($newdata = array(), $newval = '') { @@ -292,12 +292,12 @@ final class Session extends CI_Driver_Library { /** * Keeps existing flashdata available to next request. * - * @param string Item key - * @return void + * @param string Item key + * @return void */ public function keep_flashdata($key) { - // 'old' flashdata gets removed. Here we mark all + // 'old' flashdata gets removed. Here we mark all // flashdata as 'new' to preserve it from _flashdata_sweep() $old_flashdata_key = self::FLASHDATA_KEY.self::FLASHDATA_OLD.$key; $value = $this->userdata($old_flashdata_key); @@ -309,8 +309,8 @@ final class Session extends CI_Driver_Library { /** * Fetch a specific flashdata item from the session array * - * @param string Item key - * @return string + * @param string Item key + * @return string */ public function flashdata($key) { @@ -323,10 +323,10 @@ final class Session extends CI_Driver_Library { * Add or change tempdata, only available * until expiration * - * @param mixed Item name or array of items - * @param string Item value or empty string - * @param int Item lifetime in seconds or 0 for default - * @return void + * @param mixed Item name or array of items + * @param string Item value or empty string + * @param int Item lifetime in seconds or 0 for default + * @return void */ public function set_tempdata($newdata = array(), $newval = '', $expire = 0) { @@ -364,8 +364,8 @@ final class Session extends CI_Driver_Library { /** * Delete a temporary session variable from the "userdata" array * - * @param mixed Item name or array of item names - * @return void + * @param mixed Item name or array of item names + * @return void */ public function unset_tempdata($newdata = array()) { @@ -401,8 +401,8 @@ final class Session extends CI_Driver_Library { /** * Fetch a specific tempdata item from the session array * - * @param string Item key - * @return string + * @param string Item key + * @return string */ public function tempdata($key) { @@ -483,32 +483,32 @@ final class Session extends CI_Driver_Library { $this->set_userdata(self::EXPIRATION_KEY, $expirations); } } -// END Session Class +// END CI_Session Class /** - * SessionDriver Class + * CI_Session_driver Class * - * Extend this class to make a new Session driver. - * A Session driver basically manages an array of name/value pairs with some sort of storage mechanism. - * To make a new driver, derive from (extend) SessionDriver. Overload the initialize method and read or create + * Extend this class to make a new CI_Session driver. + * A CI_Session driver basically manages an array of name/value pairs with some sort of storage mechanism. + * To make a new driver, derive from (extend) CI_Session_driver. Overload the initialize method and read or create * session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler * to remove deleted data (sess_destroy), and an access handler to expose the data (get_userdata). - * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the application - * directory, the system directory, or any path you add with $CI->load->add_package_path(). - * Your driver must be named Session_, where is capitalized, and your filename must be Session_.EXT, - * preferably also capitalized. (e.g.: Session_Foo in libraries/Session/drivers/Session_Foo.php) - * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the Session + * Put your driver in the libraries/Session/drivers folder anywhere in the loader paths. This includes the + * application directory, the system directory, or any path you add with $CI->load->add_package_path(). + * Your driver must be named CI_Session_, and your filename must be Session_.php, + * preferably also capitalized. (e.g.: CI_Session_foo in libraries/Session/drivers/Session_foo.php) + * Then specify the driver by setting 'sess_driver' in your config file or as a parameter when loading the CI_Session * object. (e.g.: $config['sess_driver'] = 'foo'; OR $CI->load->driver('session', array('sess_driver' => 'foo')); ) * Already provided are the Native driver, which manages the native PHP $_SESSION array, and * the Cookie driver, which manages the data in a browser cookie, with optional extra storage in a database table. * - * @package CodeIgniter - * @subpackage Libraries + * @package CodeIgniter + * @subpackage Libraries * @category Sessions - * @author Darren Hill (DChill) + * @author ExpressionEngine Dev Team */ -abstract class SessionDriver extends CI_Driver { +abstract class CI_Session_driver extends CI_Driver { /** * Decorate * @@ -531,8 +531,8 @@ abstract class SessionDriver extends CI_Driver { * * Handles access to the parent driver library's methods * - * @param string Library method name - * @param array Method arguments (default: none) + * @param string Library method name + * @param array Method arguments (default: none) * @return mixed */ public function __call($method, $args = array()) @@ -545,7 +545,7 @@ abstract class SessionDriver extends CI_Driver { /** * Initialize driver * - * @return void + * @return void */ protected function initialize() { @@ -558,7 +558,7 @@ abstract class SessionDriver extends CI_Driver { * Data in the array has changed - perform any storage synchronization necessary * The child class MUST implement this abstract method! * - * @return void + * @return void */ abstract public function sess_save(); @@ -568,7 +568,7 @@ abstract class SessionDriver extends CI_Driver { * Clean up storage for this session - it has been terminated * The child class MUST implement this abstract method! * - * @return void + * @return void */ abstract public function sess_destroy(); @@ -578,22 +578,22 @@ abstract class SessionDriver extends CI_Driver { * Regenerate the session id * The child class MUST implement this abstract method! * - * @param boolean Destroy session data flag (default: false) - * @return void + * @param boolean Destroy session data flag (default: false) + * @return void */ abstract public function sess_regenerate($destroy = false); /** * Get a reference to user data array * - * Give array access to the main Session object + * Give array access to the main CI_Session object * The child class MUST implement this abstract method! * - * @return array Reference to userdata + * @return array Reference to userdata */ abstract public function &get_userdata(); } -// END SessionDriver Class +// END CI_Session_driver Class /* End of file Session.php */ diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 0982b1e01..d26ab0432 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -24,9 +24,9 @@ * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author ExpressionEngine Dev Team and Darren Hill (DChill42) + * @author ExpressionEngine Dev Team */ -class Session_Cookie extends SessionDriver { +class CI_Session_cookie extends CI_Session_driver { private $sess_encrypt_cookie = FALSE; private $sess_use_database = FALSE; private $sess_table_name = ''; @@ -576,8 +576,8 @@ class Session_Cookie extends SessionDriver { } } } -// END Session_Cookie Class +// END CI_Session_cookie Class /* End of file Session_cookie.php */ -/* Location: ./system/libraries/Session/Session.php */ +/* Location: ./system/libraries/Session/drivers/Session_cookie.php */ ?> diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index df588175f..37da3445a 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -22,9 +22,9 @@ * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author Darren Hill (DChill) + * @author ExpressionEngine Dev Team */ -class Session_Native extends SessionDriver { +class CI_Session_native extends CI_Session_driver { /** * Initialize session driver object * @@ -182,9 +182,9 @@ class Session_Native extends SessionDriver { return $_SESSION; } } -// END Session_Native Class +// END CI_Session_native Class /* End of file Session_native.php */ -/* Location: ./system/libraries/Session/Session.php */ +/* Location: ./system/libraries/Session/drivers/Session_native.php */ ?> -- cgit v1.2.3-24-g4f1b From 4d1cd4c56697bc53b5a9899089ab4c978c66e1da Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Wed, 31 Aug 2011 13:59:09 -0400 Subject: Restored errantly removed ucfirst --- system/libraries/Driver.php | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 80c0e2812..e958fc67f 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -32,29 +32,29 @@ class CI_Driver_Library { protected $valid_drivers = array(); protected $lib_name; - /** - * Get magic method - * + /** + * Get magic method + * * The first time a child is used it won't exist, so we instantiate it * subsequents calls will go straight to the proper child. - * - * @param string Child class name - * @return object Child class - */ + * + * @param string Child class name + * @return object Child class + */ public function __get($child) { - // Try to load the driver + // Try to load the driver return load_driver($child); - } + } - /** - * Load driver - * + /** + * Load driver + * * Separate load_driver call to support explicit driver load by library or user - * - * @param string Child class name - * @return object Child class - */ + * + * @param string Child class name + * @return object Child class + */ public function load_driver($child) { if ( ! isset($this->lib_name)) @@ -66,8 +66,8 @@ class CI_Driver_Library { $child_class = $this->lib_name.'_'.$child; // Remove the CI_ prefix and lowercase - $lib_name = strtolower(preg_replace('/^CI_/', '', $this->lib_name)); - $driver_name = strtolower(preg_replace('/^CI_/', '', $child_class)); + $lib_name = ucfirst(strtolower(str_replace('CI_', '', $this->lib_name))); + $driver_name = strtolower(str_replace('CI_', '', $child_class)); if (in_array($driver_name, array_map('strtolower', $this->valid_drivers))) { -- cgit v1.2.3-24-g4f1b From 6fbf6bd1dfa2ef373fc8072c52f63446cdd00327 Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Wed, 31 Aug 2011 14:15:35 -0400 Subject: Missed whitespace on Driver --- system/libraries/Driver.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index e958fc67f..77476e139 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -32,29 +32,29 @@ class CI_Driver_Library { protected $valid_drivers = array(); protected $lib_name; - /** - * Get magic method - * + /** + * Get magic method + * * The first time a child is used it won't exist, so we instantiate it * subsequents calls will go straight to the proper child. - * - * @param string Child class name - * @return object Child class - */ + * + * @param string Child class name + * @return object Child class + */ public function __get($child) { - // Try to load the driver + // Try to load the driver return load_driver($child); - } + } - /** - * Load driver - * + /** + * Load driver + * * Separate load_driver call to support explicit driver load by library or user - * - * @param string Child class name - * @return object Child class - */ + * + * @param string Child class name + * @return object Child class + */ public function load_driver($child) { if ( ! isset($this->lib_name)) -- cgit v1.2.3-24-g4f1b From a2ae6571e55d5a3d23645e96929eea996e9f0499 Mon Sep 17 00:00:00 2001 From: Darren Hill Date: Thu, 1 Sep 2011 07:36:26 -0400 Subject: Made private members protected for inheritance --- system/libraries/Session/Session.php | 18 +++--- .../libraries/Session/drivers/Session_cookie.php | 66 +++++++++++----------- .../libraries/Session/drivers/Session_native.php | 28 ++++----- 3 files changed, 56 insertions(+), 56 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index dacc249c5..7c340ccca 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -38,10 +38,10 @@ * @author ExpressionEngine Dev Team * @link http://codeigniter.com/user_guide/libraries/sessions.html */ -final class CI_Session extends CI_Driver_Library { +class CI_Session extends CI_Driver_Library { public $params = array(); - private $current = null; - private $userdata = array(); + protected $current = null; + protected $userdata = array(); const FLASHDATA_KEY = 'flash'; const FLASHDATA_NEW = ':new:'; @@ -415,10 +415,10 @@ final class CI_Session extends CI_Driver_Library { * Identifies flashdata as 'old' for removal * when _flashdata_sweep() runs. * - * @access private + * @access protected * @return void */ - private function _flashdata_mark() + protected function _flashdata_mark() { $userdata = $this->all_userdata(); foreach ($userdata as $name => $value) @@ -436,10 +436,10 @@ final class CI_Session extends CI_Driver_Library { /** * Removes all flashdata marked as 'old' * - * @access private + * @access protected * @return void */ - private function _flashdata_sweep() + protected function _flashdata_sweep() { $userdata = $this->all_userdata(); foreach ($userdata as $key => $value) @@ -454,10 +454,10 @@ final class CI_Session extends CI_Driver_Library { /** * Removes all expired tempdata * - * @access private + * @access protected * @return void */ - private function _tempdata_sweep() + protected function _tempdata_sweep() { // Get expirations list $expirations = $this->userdata(self::EXPIRATION_KEY); diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index d26ab0432..334218ec2 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -27,23 +27,23 @@ * @author ExpressionEngine Dev Team */ class CI_Session_cookie extends CI_Session_driver { - private $sess_encrypt_cookie = FALSE; - private $sess_use_database = FALSE; - private $sess_table_name = ''; - private $sess_expiration = 7200; - private $sess_expire_on_close = FALSE; - private $sess_match_ip = FALSE; - private $sess_match_useragent = TRUE; - private $sess_cookie_name = 'ci_session'; - private $cookie_prefix = ''; - private $cookie_path = ''; - private $cookie_domain = ''; - private $sess_time_to_update = 300; - private $encryption_key = ''; - private $time_reference = 'time'; - private $userdata = array(); - private $CI = null; - private $now = 0; + protected $sess_encrypt_cookie = FALSE; + protected $sess_use_database = FALSE; + protected $sess_table_name = ''; + protected $sess_expiration = 7200; + protected $sess_expire_on_close = FALSE; + protected $sess_match_ip = FALSE; + protected $sess_match_useragent = TRUE; + protected $sess_cookie_name = 'ci_session'; + protected $cookie_prefix = ''; + protected $cookie_path = ''; + protected $cookie_domain = ''; + protected $sess_time_to_update = 300; + protected $encryption_key = ''; + protected $time_reference = 'time'; + protected $userdata = array(); + protected $CI = null; + protected $now = 0; const gc_probability = 5; @@ -224,10 +224,10 @@ class CI_Session_cookie extends CI_Session_driver { /** * Fetch the current session data if it exists * - * @access private + * @access protected * @return bool */ - private function _sess_read() + protected function _sess_read() { // Fetch the cookie $session = $this->CI->input->cookie($this->sess_cookie_name); @@ -343,10 +343,10 @@ class CI_Session_cookie extends CI_Session_driver { /** * Create a new session * - * @access private + * @access protected * @return void */ - private function _sess_create() + protected function _sess_create() { $sessid = ''; while (strlen($sessid) < 32) @@ -376,11 +376,11 @@ class CI_Session_cookie extends CI_Session_driver { /** * Update an existing session * - * @access private + * @access protected * @param boolean Force update flag (default: false) * @return void */ - private function _sess_update($force = false) + protected function _sess_update($force = false) { // We only update the session every five minutes by default (unless forced) if (!$force && ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now()) @@ -433,10 +433,10 @@ class CI_Session_cookie extends CI_Session_driver { /** * Get the "now" time * - * @access private + * @access protected * @return int */ - private function _get_time() + protected function _get_time() { if (strtolower($this->time_reference) == 'gmt') { @@ -455,11 +455,11 @@ class CI_Session_cookie extends CI_Session_driver { /** * Write the session cookie * - * @access private + * @access protected * @param array Cookie name/value pairs * @return void */ - private function _set_cookie(array $cookie_data = NULL) + protected function _set_cookie(array $cookie_data = NULL) { if (is_null($cookie_data)) { @@ -491,11 +491,11 @@ class CI_Session_cookie extends CI_Session_driver { * This function first converts any slashes found in the array to a temporary * marker, so when it gets unserialized the slashes will be preserved * - * @access private + * @access protected * @param mixed Data to serialize * @return string */ - private function _serialize($data) + protected function _serialize($data) { if (is_array($data)) { @@ -524,11 +524,11 @@ class CI_Session_cookie extends CI_Session_driver { * This function unserializes a data string, then converts any * temporary slash markers back to actual slashes * - * @access private + * @access protected * @param string Data to unserialize * @return mixed */ - private function _unserialize($data) + protected function _unserialize($data) { $data = @unserialize(strip_slashes($data)); @@ -554,10 +554,10 @@ class CI_Session_cookie extends CI_Session_driver { * This deletes expired session rows from database * if the probability percentage is met * - * @access private + * @access protected * @return void */ - private function _sess_gc() + protected function _sess_gc() { if ($this->sess_use_database != TRUE) { diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 37da3445a..c7130b688 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -5,11 +5,11 @@ * An open source application development framework for PHP 5.1.6 or newer * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. + * @author ExpressionEngine Dev Team + * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. * @license http://codeigniter.com/user_guide/license.html * @link http://codeigniter.com - * @since Version 2.0 + * @since Version 2.0 * @filesource */ @@ -22,13 +22,13 @@ * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author ExpressionEngine Dev Team + * @author ExpressionEngine Dev Team */ class CI_Session_native extends CI_Session_driver { /** * Initialize session driver object * - * @access protected + * @access protected * @return void */ protected function initialize() @@ -126,8 +126,8 @@ class CI_Session_native extends CI_Session_driver { /** * Save the session data * - * @access public - * @return void + * @access public + * @return void */ public function sess_save() { @@ -137,8 +137,8 @@ class CI_Session_native extends CI_Session_driver { /** * Destroy the current session * - * @access public - * @return void + * @access public + * @return void */ public function sess_destroy() { @@ -160,9 +160,9 @@ class CI_Session_native extends CI_Session_driver { * * Regenerate the session id * - * @access public - * @param boolean Destroy session data flag (default: false) - * @return void + * @access public + * @param boolean Destroy session data flag (default: false) + * @return void */ public function sess_regenerate($destroy = false) { @@ -173,8 +173,8 @@ class CI_Session_native extends CI_Session_driver { /** * Get a reference to user data array * - * @access public - * @return array Reference to userdata + * @access public + * @return array Reference to userdata */ public function &get_userdata() { -- cgit v1.2.3-24-g4f1b From 2139ecdbe882dee32f60de5aec74ec2b8a509b7a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 11 Jan 2012 23:58:50 +0200 Subject: Added date_range() to the Date helper --- system/helpers/date_helper.php | 166 +++++++++++++++++++++++++- user_guide_src/source/changelog.rst | 3 +- user_guide_src/source/helpers/date_helper.rst | 24 ++++ 3 files changed, 191 insertions(+), 2 deletions(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 9e58d8630..4a0791a43 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -695,5 +695,169 @@ if ( ! function_exists('timezones')) } } +// ------------------------------------------------------------------------ + +/** + * Date range + * + * Returns a list of dates within a specified period. + * + * @access public + * @param int unix_start UNIX timestamp of period start date + * @param int unix_end|days UNIX timestamp of period end date + * or interval in days. + * @param mixed is_unix Specifies wether the second @param + * is a UNIX timestamp or day interval + * - TRUE or 'unix' for a timestamp + * - FALSE or 'days' for an interval + * @param string date_format Output date format, same as in date() + * @return array + */ +if ( ! function_exists('date_range')) +{ + function date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d') + { + if ($unix_start == '' OR $mixed == '' OR $format == '') + { + return FALSE; + } + + $is_unix = ! ( ! $is_unix OR $is_unix === 'days'); + + // Validate input and try strtotime() on invalid timestamps/intervals, just in case + if ( ( ! preg_match('/^[0-9]+$/', $unix_start) && ($unix_start = @strtotime($unix_time)) === FALSE) + OR ( ! preg_match('/^[0-9]+$/', $mixed) && ($is_unix === FALSE OR ($mixed = @strtotime($mixed)) === FALSE)) + OR ($is_unix === TRUE && $mixed < $unix_start)) + { + return FALSE; + } + + if ($is_unix && ($unix_start == $mixed OR date($format, $unix_start) === date($format, $mixed))) + { + return array($start_date); + } + + $range = array(); + + if (is_php('5.2')) + { + /* NOTE: Even though the DateTime object has many useful features, it appears that + * it doesn't always handle properly timezones, when timestamps are passed + * directly to its constructor. Neither of the following gave proper results: + * + * new DateTime('') + * new DateTime('', '') + * + * --- available in PHP 5.3: + * + * DateTime::createFromFormat('', '') + * DateTime::createFromFormat('', '', 'setTimestamp($unix_start); + if ($is_unix) + { + $arg = new DateTime(); + $arg->setTimestamp($mixed); + } + else + { + $arg = (int) $mixed; + } + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); + $range = array(); + foreach ($period as $date) + { + $range[] = $date->format($format); + } + + /* If a period end date was passed to the DatePeriod constructor, it might not + * be in our results. Not sure if this is a bug or it's just possible because + * the end date might actually be less than 24 hours away from the previously + * generated DateTime object, but either way - we have to append it manually. + */ + if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) + { + $range[] = $arg->format($format); + } + + return $range; + } + + $from->setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); + $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); + if ($is_unix) + { + $arg = new DateTime(); + $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); + $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); + } + else + { + $arg = (int) $mixed; + } + $range[] = $from->format($format); + + if (is_int($arg)) // Day intervals + { + do + { + $from->modify('+1 day'); + $range[] = $from->format($format); + } + while (--$arg > 0); + } + else // end date UNIX timestamp + { + for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day')) + { + $range[] = $from->format($format); + } + + // Our loop only appended dates prior to our end date + $range[] = $arg->format($format); + } + + return $range; + } + + /* ---------------------------------------------------------------------------------- + * PHP Version is < 5.2. We have no other option, but to calculate manually ... + * + * NOTE: If we do something like this: + * + * $unix_timestamp + 86400 + * + * ... due to DST, there's a possibility of calculation errors and/or incorrect + * hours generated (if the specified format displays such data) due to DST. + */ + + $from = $to = array(); + sscanf(date('Y-n-j G:i:s', $unix_start), '%d-%d-%d %d:%d:%d', $from['y'], $from['mo'], $from['d'], $from['h'], $from['mi'], $from['s']); + + // If we don't have the end timestamp, let mktime() calculate it + $unix_end = ($is_unix) ? (int) $mixed : mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'] + $mixed, $from['y']); + + $end_check = date('Ymd', $unix_end); + while (date('Ymd', $unix_start = mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'], $from['y'])) !== $end_check) + { + $range[] = date($format, $unix_start); + $from['d']++; + } + + // Our loop only appended dates prior to our end date + $range[] = date($format, $unix_end); + + return $range; + } +} + /* End of file date_helper.php */ -/* Location: ./system/helpers/date_helper.php */ \ No newline at end of file +/* Location: ./system/helpers/date_helper.php */ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 48011f208..613ef7881 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -38,7 +38,8 @@ Release Date: Not Released - url_title() will now trim extra dashes from beginning and end. - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper `. - - Changed humanize to include a second param for the separator. + - Changed humanize() to include a second param for the separator. + - Added date_range() to the :doc:`Date Helper `. - Database diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index ad06dd628..f965e6166 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -296,6 +296,30 @@ Example If the second parameter is empty, the current year will be used. +date_range() +============ + +Returns a list of dates within a specified period. + +.. php:method:: date_range($unix_start = '', $mixed = '', $is_unix = TRUE, $format = 'Y-m-d') + + :param integer $unix_start: UNIX timestamp of the range start date + :param integer $mixed: UNIX timestamp of the range end date or interval in days + :param boolean $is_unix: set to FALSE if $mixed is not a timestamp + :param string $format: output date format, same as in date() + :returns: array + +Example + +:: + + $range = date_range('2012-01-01', '2012-01-15'); + echo "First 15 days of 2012:"; + foreach ($range as $date) + { + echo $date."\n"; + } + timezones() =========== -- cgit v1.2.3-24-g4f1b From 4f553dfe20a3dcb2d384fe30210d85cf4f645de2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 15 Jan 2012 15:03:02 +0200 Subject: Remove a space :) --- system/helpers/date_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 4a0791a43..7bec8079d 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -745,7 +745,7 @@ if ( ! function_exists('date_range')) * it doesn't always handle properly timezones, when timestamps are passed * directly to its constructor. Neither of the following gave proper results: * - * new DateTime('') + * new DateTime('') * new DateTime('', '') * * --- available in PHP 5.3: -- cgit v1.2.3-24-g4f1b From 8bbb38983b8052e32063244941315fe81199e024 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 21 Feb 2012 22:22:34 +0200 Subject: Removed a second/unnecessary variable initialization and fixed a comment --- system/helpers/date_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 7bec8079d..b186b2acb 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -771,8 +771,8 @@ if ( ! function_exists('date_range')) { $arg = (int) $mixed; } + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); - $range = array(); foreach ($period as $date) { $range[] = $date->format($format); @@ -836,7 +836,7 @@ if ( ! function_exists('date_range')) * $unix_timestamp + 86400 * * ... due to DST, there's a possibility of calculation errors and/or incorrect - * hours generated (if the specified format displays such data) due to DST. + * hours generated (if the specified format displays such data). */ $from = $to = array(); -- cgit v1.2.3-24-g4f1b From 30da39bb5d65c37203c12a42dfc50f7d231fb2d1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 10 Mar 2012 15:49:17 +0200 Subject: Remove PHP 5.1 dependancy check --- system/helpers/date_helper.php | 152 ++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 92 deletions(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index a655c1f21..cb15f6df6 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -739,121 +739,89 @@ if ( ! function_exists('date_range')) $range = array(); - if (is_php('5.2')) - { - /* NOTE: Even though the DateTime object has many useful features, it appears that - * it doesn't always handle properly timezones, when timestamps are passed - * directly to its constructor. Neither of the following gave proper results: - * - * new DateTime('') - * new DateTime('', '') - * - * --- available in PHP 5.3: - * - * DateTime::createFromFormat('', '') - * DateTime::createFromFormat('', '', 'setTimestamp($unix_start); - if ($is_unix) - { - $arg = new DateTime(); - $arg->setTimestamp($mixed); - } - else - { - $arg = (int) $mixed; - } - - $period = new DatePeriod($from, new DateInterval('P1D'), $arg); - foreach ($period as $date) - { - $range[] = $date->format($format); - } - - /* If a period end date was passed to the DatePeriod constructor, it might not - * be in our results. Not sure if this is a bug or it's just possible because - * the end date might actually be less than 24 hours away from the previously - * generated DateTime object, but either way - we have to append it manually. - */ - if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) - { - $range[] = $arg->format($format); - } - - return $range; - } + /* NOTE: Even though the DateTime object has many useful features, it appears that + * it doesn't always handle properly timezones, when timestamps are passed + * directly to its constructor. Neither of the following gave proper results: + * + * new DateTime('') + * new DateTime('', '') + * + * --- available in PHP 5.3: + * + * DateTime::createFromFormat('', '') + * DateTime::createFromFormat('', '', 'setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); - $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); + if (is_php('5.3')) + { + $from->setTimestamp($unix_start); if ($is_unix) { $arg = new DateTime(); - $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); - $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); + $arg->setTimestamp($mixed); } else { $arg = (int) $mixed; } - $range[] = $from->format($format); - if (is_int($arg)) // Day intervals + $period = new DatePeriod($from, new DateInterval('P1D'), $arg); + foreach ($period as $date) { - do - { - $from->modify('+1 day'); - $range[] = $from->format($format); - } - while (--$arg > 0); + $range[] = $date->format($format); } - else // end date UNIX timestamp - { - for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day')) - { - $range[] = $from->format($format); - } - // Our loop only appended dates prior to our end date + /* If a period end date was passed to the DatePeriod constructor, it might not + * be in our results. Not sure if this is a bug or it's just possible because + * the end date might actually be less than 24 hours away from the previously + * generated DateTime object, but either way - we have to append it manually. + */ + if ( ! is_int($arg) && $range[count($range) - 1] !== $arg->format($format)) + { $range[] = $arg->format($format); } return $range; } - /* ---------------------------------------------------------------------------------- - * PHP Version is < 5.2. We have no other option, but to calculate manually ... - * - * NOTE: If we do something like this: - * - * $unix_timestamp + 86400 - * - * ... due to DST, there's a possibility of calculation errors and/or incorrect - * hours generated (if the specified format displays such data). - */ - - $from = $to = array(); - sscanf(date('Y-n-j G:i:s', $unix_start), '%d-%d-%d %d:%d:%d', $from['y'], $from['mo'], $from['d'], $from['h'], $from['mi'], $from['s']); - - // If we don't have the end timestamp, let mktime() calculate it - $unix_end = ($is_unix) ? (int) $mixed : mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'] + $mixed, $from['y']); + $from->setDate(date('Y', $unix_start), date('n', $unix_start), date('j', $unix_start)); + $from->setTime(date('G', $unix_start), date('i', $unix_start), date('s', $unix_start)); + if ($is_unix) + { + $arg = new DateTime(); + $arg->setDate(date('Y', $mixed), date('n', $mixed), date('j', $mixed)); + $arg->setTime(date('G', $mixed), date('i', $mixed), date('s', $mixed)); + } + else + { + $arg = (int) $mixed; + } + $range[] = $from->format($format); - $end_check = date('Ymd', $unix_end); - while (date('Ymd', $unix_start = mktime($from['h'], $from['mi'], $from['s'], $from['mo'], $from['d'], $from['y'])) !== $end_check) + if (is_int($arg)) // Day intervals { - $range[] = date($format, $unix_start); - $from['d']++; + do + { + $from->modify('+1 day'); + $range[] = $from->format($format); + } + while (--$arg > 0); } + else // end date UNIX timestamp + { + for ($from->modify('+1 day'), $end_check = $arg->format('Ymd'); $from->format('Ymd') < $end_check; $from->modify('+1 day')) + { + $range[] = $from->format($format); + } - // Our loop only appended dates prior to our end date - $range[] = date($format, $unix_end); + // Our loop only appended dates prior to our end date + $range[] = $arg->format($format); + } return $range; } -- cgit v1.2.3-24-g4f1b From ad97736d8249240cba802d33a24b7b11e02488cf Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 13 Mar 2012 12:51:50 +0200 Subject: Remove access description comment --- system/helpers/date_helper.php | 1 - 1 file changed, 1 deletion(-) diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index cb15f6df6..ead0d1723 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -702,7 +702,6 @@ if ( ! function_exists('timezones')) * * Returns a list of dates within a specified period. * - * @access public * @param int unix_start UNIX timestamp of period start date * @param int unix_end|days UNIX timestamp of period end date * or interval in days. -- cgit v1.2.3-24-g4f1b From 58dfc089bf5b0ca35c2ff244e5bfdff726f9adcd Mon Sep 17 00:00:00 2001 From: Melounek Date: Fri, 29 Jun 2012 08:43:47 +0200 Subject: added parameter for returned-path in Email::from() --- system/libraries/Email.php | 17 +++++++++++++---- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/libraries/email.rst | 7 +++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index dd5477e05..9270d5fca 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -188,7 +188,7 @@ class CI_Email { * @param string * @return object */ - public function from($from, $name = '') + public function from($from, $name = '', $return_path = '') { if (preg_match('/\<(.*)\>/', $from, $match)) { @@ -198,6 +198,10 @@ class CI_Email { if ($this->validate) { $this->validate_email($this->_str_to_array($from)); + if($return_path) + { + $this->validate_email($this->_str_to_array($return_path)); + } } // prepare the display name @@ -216,7 +220,12 @@ class CI_Email { } $this->set_header('From', $name.' <'.$from.'>'); - $this->set_header('Return-Path', '<'.$from.'>'); + + if(!$return_path) + { + $return_path = $from; + } + $this->set_header('Return-Path', '<'.$return_path.'>'); return $this; } @@ -1385,7 +1394,7 @@ class CI_Email { { // most documentation of sendmail using the "-f" flag lacks a space after it, however // we've encountered servers that seem to require it to be in place. - return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['From'])); + return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str, '-f '.$this->clean_email($this->_headers['Return-Path'])); } } @@ -1398,7 +1407,7 @@ class CI_Email { */ protected function _send_with_sendmail() { - $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t', 'w'); + $fp = @popen($this->mailpath.' -oi -f '.$this->clean_email($this->_headers['From']).' -t'.' -r '.$this->clean_email($this->_headers['Return-Path']), 'w'); if ($fp === FALSE OR $fp === NULL) { diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 28e2f94bb..4f5915de8 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -138,6 +138,7 @@ Release Date: Not Released - CI_Loader::_ci_autoloader() is now a protected method. - Added custom filename to Email::attach() as $this->email->attach($filename, $disposition, $newname). - Added possibility to send attachment as buffer string in Email::attach() as $this->email->attach($buffer, $disposition, $newname, $mime). + - Added third parameter $return_path for method Email::from(). - :doc:`Cart library ` changes include: - It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites. - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe". diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst index f99eb91df..8d2549d11 100644 --- a/user_guide_src/source/libraries/email.rst +++ b/user_guide_src/source/libraries/email.rst @@ -117,6 +117,13 @@ Sets the email address and name of the person sending the email:: $this->email->from('you@example.com', 'Your Name'); +:: + + $this->email->from('you@example.com', 'Your Name', 'returned_emails@example.com'); + +Third parameter is redirect for undelivered emails (may not be configured with +protocol 'smtp'). + $this->email->reply_to() ------------------------- -- cgit v1.2.3-24-g4f1b From cccd07509ee3c924e0172e8bff216acef0aa9f86 Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Wed, 11 Jul 2012 03:19:03 -0500 Subject: Testing push. Will revert. --- license.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license.txt b/license.txt index 395dcc3a0..c96b50764 100644 --- a/license.txt +++ b/license.txt @@ -31,7 +31,7 @@ the following: non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, -have made, and import the Original Work and Derivative Works. +have made, and import the Original Work and Derivative Works. 3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available -- cgit v1.2.3-24-g4f1b From 6bf1e50bdff62d4842cd5a94d324e0768c5ace3e Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Wed, 11 Jul 2012 03:25:41 -0500 Subject: Revert "Testing push. Will revert." This reverts commit cccd07509ee3c924e0172e8bff216acef0aa9f86. --- license.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/license.txt b/license.txt index c96b50764..395dcc3a0 100644 --- a/license.txt +++ b/license.txt @@ -31,7 +31,7 @@ the following: non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, -have made, and import the Original Work and Derivative Works. +have made, and import the Original Work and Derivative Works. 3) Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available -- cgit v1.2.3-24-g4f1b From 42b77a9a1a5d4ec7ceb94b421b12af9c442769ba Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 23 Jul 2012 11:28:42 -0400 Subject: Made cookie driver default and did miniscule code cleanup on drivers --- system/libraries/Session/Session.php | 2 +- system/libraries/Session/drivers/Session_cookie.php | 9 ++------- system/libraries/Session/drivers/Session_native.php | 3 --- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 94fb4b10a..474ca9c7a 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -84,7 +84,7 @@ class CI_Session extends CI_Driver_Library { // Get driver to load $key = 'sess_driver'; $driver = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); - if (!$driver) $driver = 'native'; + if (!$driver) $driver = 'cookie'; if (!in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers))) { $this->valid_drivers[] = 'Session_'.$driver; diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 0dc109bd1..255a1ae3e 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -39,7 +39,6 @@ * @link http://codeigniter.com/user_guide/libraries/sessions.html */ class CI_Session_cookie extends CI_Session_driver { - /** * Whether to encrypt the session cookie * @@ -152,7 +151,6 @@ class CI_Session_cookie extends CI_Session_driver { */ public $time_reference = 'local'; - /** * Session data * @@ -186,7 +184,7 @@ class CI_Session_cookie extends CI_Session_driver { $this->CI =& get_instance(); // Set all the session preferences, which can either be set - // manually via the $params array above or via the config file + // manually via the $params array or via the config file foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', @@ -527,9 +525,7 @@ class CI_Session_cookie extends CI_Session_driver { // by pushing all userdata to the cookie. $cookie_data = NULL; - /* Changing the session ID during an AJAX call causes problems, - * so we'll only update our last_activity - */ + // Changing the session ID during an AJAX call causes problems, so we'll only update our last_activity if ($this->CI->input->is_ajax_request()) { $this->userdata['last_activity'] = $this->now; @@ -752,7 +748,6 @@ class CI_Session_cookie extends CI_Session_driver { log_message('debug', 'Session garbage collection performed.'); } } - } /* End of file Session_cookie.php */ diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 09fb7f999..7fbe9f89e 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -182,9 +182,6 @@ class CI_Session_native extends CI_Session_driver { return $_SESSION; } } -// END CI_Session_native Class - /* End of file Session_native.php */ /* Location: ./system/libraries/Session/drivers/Session_native.php */ -?> -- cgit v1.2.3-24-g4f1b From 77ee3fdac34d317b600a269e0b845588c88fa4c5 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 24 Jul 2012 11:50:01 -0400 Subject: Cleaned up bangs and lowercase booleans, and fixed userdata return on not found to NULL --- system/libraries/Session/Session.php | 18 +++++++++--------- system/libraries/Session/drivers/Session_cookie.php | 2 +- system/libraries/Session/drivers/Session_native.php | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 474ca9c7a..9c887d88e 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -69,12 +69,12 @@ class CI_Session extends CI_Driver_Library { $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); if ($drivers) { - if (!is_array($drivers)) $drivers = array($drivers); + if ( ! is_array($drivers)) $drivers = array($drivers); // Add driver names to valid list foreach ($drivers as $driver) { - if (!in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers))) + if ( ! in_array(strtolower($driver), array_map('strtolower', $this->valid_drivers))) { $this->valid_drivers[] = $driver; } @@ -84,8 +84,8 @@ class CI_Session extends CI_Driver_Library { // Get driver to load $key = 'sess_driver'; $driver = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); - if (!$driver) $driver = 'cookie'; - if (!in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers))) + if ( ! $driver) $driver = 'cookie'; + if ( ! in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers))) { $this->valid_drivers[] = 'Session_'.$driver; } @@ -182,7 +182,7 @@ class CI_Session extends CI_Driver_Library { public function userdata($item) { // Return value or FALSE if not found - return (!isset($this->userdata[$item])) ? FALSE : $this->userdata[$item]; + return ( ! isset($this->userdata[$item])) ? NULL : $this->userdata[$item]; } /** @@ -193,7 +193,7 @@ class CI_Session extends CI_Driver_Library { public function all_userdata() { // Return entire array - return (!isset($this->userdata)) ? FALSE : $this->userdata; + return ( ! isset($this->userdata)) ? NULL : $this->userdata; } /** @@ -362,7 +362,7 @@ class CI_Session extends CI_Driver_Library { // Get or create expiration list $expirations = $this->userdata(self::EXPIRATION_KEY); - if (!$expirations) + if ( ! $expirations) { $expirations = array(); } @@ -392,7 +392,7 @@ class CI_Session extends CI_Driver_Library { { // Get expirations list $expirations = $this->userdata(self::EXPIRATION_KEY); - if (!$expirations || !count($expirations)) + if ( ! $expirations || ! count($expirations)) { // Nothing to do return; @@ -482,7 +482,7 @@ class CI_Session extends CI_Driver_Library { { // Get expirations list $expirations = $this->userdata(self::EXPIRATION_KEY); - if (!$expirations || !count($expirations)) + if ( ! $expirations || ! count($expirations)) { // Nothing to do return; diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 255a1ae3e..e39ada052 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -516,7 +516,7 @@ class CI_Session_cookie extends CI_Session_driver { protected function _sess_update($force = FALSE) { // We only update the session every five minutes by default (unless forced) - if (!$force && ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) + if ( ! $force && ($this->userdata['last_activity'] + $this->sess_time_to_update) >= $this->now) { return; } diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 7fbe9f89e..8388e06b5 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -161,10 +161,10 @@ class CI_Session_native extends CI_Session_driver { * Regenerate the session id * * @access public - * @param boolean Destroy session data flag (default: false) + * @param boolean Destroy session data flag (default: FALSE) * @return void */ - public function sess_regenerate($destroy = false) + public function sess_regenerate($destroy = FALSE) { // Just regenerate id, passing destroy flag session_regenerate_id($destroy); -- cgit v1.2.3-24-g4f1b From c58722535e0358367f351c168480ef98a033264c Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 30 Jul 2012 14:53:11 -0400 Subject: Fixed _parent references and several minor bugs --- system/libraries/Driver.php | 2 +- system/libraries/Session/Session.php | 14 +++++----- .../libraries/Session/drivers/Session_cookie.php | 30 +++++++++++++++++++--- .../libraries/Session/drivers/Session_native.php | 2 +- 4 files changed, 35 insertions(+), 13 deletions(-) diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 86b233a15..1d084c8e4 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -65,7 +65,7 @@ class CI_Driver_Library { public function __get($child) { // Try to load the driver - return load_driver($child); + return $this->load_driver($child); } /** diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 9c887d88e..734334249 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -64,7 +64,7 @@ class CI_Session extends CI_Driver_Library { // Get valid drivers list $CI =& get_instance(); - $this->valid_drivers = array('CI_Session_native', 'CI_Session_cookie'); + $this->valid_drivers = array('Session_native', 'Session_cookie'); $key = 'sess_valid_drivers'; $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); if ($drivers) @@ -131,7 +131,7 @@ class CI_Session extends CI_Driver_Library { public function select_driver($driver) { // Validate driver name - $lowername = strtolower($driver); + $lowername = strtolower(str_replace('CI_', '', $driver)); if (in_array($lowername, array_map('strtolower', $this->valid_drivers))) { // See if regular or lowercase variant is loaded @@ -177,11 +177,11 @@ class CI_Session extends CI_Driver_Library { * Fetch a specific item from the session array * * @param string Item key - * @return string Item value + * @return string Item value or NULL if not found */ public function userdata($item) { - // Return value or FALSE if not found + // Return value or NULL if not found return ( ! isset($this->userdata[$item])) ? NULL : $this->userdata[$item]; } @@ -208,7 +208,7 @@ class CI_Session extends CI_Driver_Library { // loop through all userdata foreach ($this->all_userdata() as $key => $val) { - // if it contains flashdata, add it + // if it contains flashdata, add it if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) { $out[$key] = $val; @@ -543,7 +543,7 @@ abstract class CI_Session_driver extends CI_Driver { // Call base class decorate first parent::decorate($parent); - // Call initialize method now that driver has access to $this->parent + // Call initialize method now that driver has access to $this->_parent $this->initialize(); } @@ -559,7 +559,7 @@ abstract class CI_Session_driver extends CI_Driver { public function __call($method, $args = array()) { // Make sure the parent library uses this driver - $this->parent->select_driver(get_class($this)); + $this->_parent->select_driver(get_class($this)); return parent::__call($method, $args); } diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index e39ada052..19ccd417d 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -190,13 +190,13 @@ class CI_Session_cookie extends CI_Session_driver { 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', 'encryption_key') as $key) { - $this->$key = isset($this->parent->params[$key]) ? $this->parent->params[$key] : + $this->$key = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : $this->CI->config->item($key); } if ($this->encryption_key === '') { - show_error('In order to use the Session Cookie driver you are required to set an encryption key '. + show_error('In order to use the Cookie Session driver you are required to set an encryption key '. 'in your config file.'); } @@ -309,7 +309,7 @@ class CI_Session_cookie extends CI_Session_driver { } // Kill the cookie - setcookie($this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000), + $this->_setcookie($this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000), $this->cookie_path, $this->cookie_domain, 0); // Kill session data @@ -632,10 +632,32 @@ class CI_Session_cookie extends CI_Session_driver { $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); // Set the cookie - setcookie($this->sess_cookie_name, $cookie_data, $expire, $this->cookie_path, $this->cookie_domain, + $this->_setcookie($this->sess_cookie_name, $cookie_data, $expire, $this->cookie_path, $this->cookie_domain, $this->cookie_secure, $this->cookie_httponly); } + /** + * Set a cookie with the system + * + * This abstraction of the setcookie call allows overriding for unit testing + * + * @access protected + * @param string Cookie name + * @param string Cookie value + * @param int Expiration time + * @param string Cookie path + * @param string Cookie domain + * @param bool Secure connection flag + * @param bool HTTP protocol only flag + * @return void + */ + protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, + $httponly = false) + { + // Set the cookie + setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); + } + /** * Serialize an array * diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 8388e06b5..27db942eb 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -39,7 +39,7 @@ class CI_Session_native extends CI_Session_driver { foreach (array('sess_cookie_name', 'sess_expire_on_close', 'sess_expiration', 'sess_match_ip', 'sess_match_useragent', 'cookie_prefix', 'cookie_path', 'cookie_domain') as $key) { - $config[$key] = isset($this->parent->params[$key]) ? $this->parent->params[$key] : $CI->config->item($key); + $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : $CI->config->item($key); } // Set session name, if specified -- cgit v1.2.3-24-g4f1b From b185537938061bf9b8f132f9f3c3992e12902be8 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 09:32:23 -0400 Subject: Fixed userdata synchronization, loaded driver check, and all_flashdata keys --- system/libraries/Session/Session.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 734334249..68819a665 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -95,7 +95,6 @@ class CI_Session extends CI_Driver_Library { // Load driver and get array reference $this->load_driver($driver); - $this->userdata =& $this->current->get_userdata(); // Delete 'old' flashdata (from last request) $this->_flashdata_sweep(); @@ -119,6 +118,7 @@ class CI_Session extends CI_Driver_Library { { // Save reference to most recently loaded driver as library default $this->current = parent::load_driver($driver); + $this->userdata =& $this->current->get_userdata(); return $this->current; } @@ -134,14 +134,12 @@ class CI_Session extends CI_Driver_Library { $lowername = strtolower(str_replace('CI_', '', $driver)); if (in_array($lowername, array_map('strtolower', $this->valid_drivers))) { - // See if regular or lowercase variant is loaded - if (class_exists($driver)) - { - $this->current = $this->$driver; - } - else if (class_exists($lowername)) + // See if driver is loaded + $child = str_replace($this->lib_name.'_', '', $driver); + if (isset($this->$child)) { - $this->current = $this->$lowername; + $this->current = $this->$child; + $this->userdata =& $this->current->get_userdata(); } else { @@ -211,6 +209,7 @@ class CI_Session extends CI_Driver_Library { // if it contains flashdata, add it if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) { + $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); $out[$key] = $val; } } -- cgit v1.2.3-24-g4f1b From 57486009573a86d9e286a49c92216ba17aae0d5a Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 09:39:53 -0400 Subject: Added Session driver library unit tests and added driver library autoloading to test framework --- tests/codeigniter/libraries/Session_test.php | 304 +++++++++++++++++++++++++++ tests/mocks/autoloader.php | 23 +- tests/mocks/libraries/session.php | 43 ++++ 3 files changed, 365 insertions(+), 5 deletions(-) create mode 100644 tests/codeigniter/libraries/Session_test.php create mode 100644 tests/mocks/libraries/session.php diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php new file mode 100644 index 000000000..db7efb6b7 --- /dev/null +++ b/tests/codeigniter/libraries/Session_test.php @@ -0,0 +1,304 @@ + 0, 'use_only_cookies' => 0, 'cache_limiter' => false); + protected $setting_vals = array(); + protected $cookie_vals; + protected $session; + + /** + * Set up test framework + */ + public function set_up() + { + // Override settings + foreach ($this->settings as $name => $value) { + $this->setting_vals[$name] = ini_get('session.'.$name); + ini_set('session.'.$name, $value); + } + + // Start with clean environment + $this->cookie_vals = $_COOKIE; + $_COOKIE = array(); + + // Establish necessary support classes + $obj = new stdClass; + foreach (array('config' => 'cfg', 'load' => 'load', 'input' => 'in') as $name => $abbr) { + $class = $this->ci_core_class($abbr); + $obj->$name = new $class; + } + $this->ci_instance($obj); + + // Attach session instance locally + $config = array('sess_encrypt_cookie' => FALSE, 'sess_use_database' => FALSE, 'sess_table_name' => '', + 'sess_expiration' => 7200, 'sess_expire_on_close' => FALSE, 'sess_match_ip' => FALSE, + 'sess_match_useragent' => TRUE, 'sess_cookie_name' => 'ci_session', 'cookie_path' => '', + 'cookie_domain' => '', 'cookie_secure' => FALSE, 'cookie_httponly' => FALSE, 'sess_time_to_update' => 300, + 'time_reference' => 'local', 'cookie_prefix' => '', 'encryption_key' => 'foobar', + 'sess_valid_drivers' => array('Mock_Libraries_Session_native', 'Mock_Libraries_Session_cookie')); + $this->session = new Mock_Libraries_Session($config); + } + + /** + * Tear down test framework + */ + public function tear_down() + { + // Restore environment + if (session_id()) session_destroy(); + $_SESSION = array(); + $_COOKIE = $this->cookie_vals; + + // Restore settings + foreach ($this->settings as $name => $value) { + ini_set('session.'.$name, $this->setting_vals[$name]); + } + } + + /** + * Test set_userdata() function + */ + public function test_set_userdata() + { + // Set a userdata message for each driver + $cmsg = 'Some test data'; + $this->session->cookie->set_userdata('test1', $cmsg); + $nmsg = 'Other test data'; + $this->session->native->set_userdata('test1', $nmsg); + + // Verify independent messages + $this->assertEquals($this->session->cookie->userdata('test1'), $cmsg); + $this->assertEquals($this->session->native->userdata('test1'), $nmsg); + } + + /** + * Test the has_userdata() function + */ + public function test_has_userdata() + { + // Set a userdata message for each driver + $cmsg = 'My test data'; + $this->session->cookie->set_userdata('test2', $cmsg); + $nmsg = 'Your test data'; + $this->session->native->set_userdata('test2', $nmsg); + + // Verify independent messages + $this->assertTrue($this->session->cookie->has_userdata('test2')); + $this->assertTrue($this->session->native->has_userdata('test2')); + } + + /** + * Test the all_userdata() function + */ + public function test_all_userdata() + { + // Set a specific series of data for each driver + $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $this->session->cookie->set_userdata($cdata); + $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); + $this->session->native->set_userdata($ndata); + + // Make sure all values are present + $call = $this->session->cookie->all_userdata(); + foreach ($cdata as $key => $value) { + $this->assertEquals($value, $call[$key]); + } + $nall = $this->session->native->all_userdata(); + foreach ($ndata as $key => $value) { + $this->assertEquals($value, $nall[$key]); + } + } + + /** + * Test the unset_userdata() function + */ + public function test_unset_userdata() + { + // Set a userdata message for each driver + $cmsg = 'Other test data'; + $this->session->cookie->set_userdata('test3', $cmsg); + $nmsg = 'Sundry test data'; + $this->session->native->set_userdata('test3', $nmsg); + + // Verify independent messages + $this->assertEquals($this->session->cookie->userdata('test3'), $cmsg); + $this->assertEquals($this->session->native->userdata('test3'), $nmsg); + + // Unset them and verify absence + $this->session->cookie->unset_userdata('test3'); + $this->session->native->unset_userdata('test3'); + $this->assertEquals($this->session->cookie->userdata('test3'), NULL); + $this->assertEquals($this->session->native->userdata('test3'), NULL); + } + + /** + * Test the set_flashdata() function + */ + public function test_set_flashdata() + { + // Set flashdata message for each driver + $cmsg = 'Some flash data'; + $this->session->cookie->set_flashdata('test4', $cmsg); + $nmsg = 'Other flash data'; + $this->session->native->set_flashdata('test4', $nmsg); + + // Simulate page reload + $this->session->cookie->reload(); + $this->session->native->reload(); + + // Verify independent messages + $this->assertEquals($this->session->cookie->flashdata('test4'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test4'), $nmsg); + + // Simulate next page reload + $this->session->cookie->reload(); + $this->session->native->reload(); + + // Verify absence of messages + $this->assertEquals($this->session->cookie->flashdata('test4'), NULL); + $this->assertEquals($this->session->native->flashdata('test4'), NULL); + } + + /** + * Test the keep_flashdata() function + */ + public function test_keep_flashdata() + { + // Set flashdata message for each driver + $cmsg = 'My flash data'; + $this->session->cookie->set_flashdata('test5', $cmsg); + $nmsg = 'Your flash data'; + $this->session->native->set_flashdata('test5', $nmsg); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + + // Keep messages + $this->session->cookie->keep_flashdata('test5'); + $this->session->native->keep_flashdata('test5'); + + // Simulate next page reload and verify message persistence + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); + $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + + // Simulate next page reload and verify absence of messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->flashdata('test5'), NULL); + $this->assertEquals($this->session->native->flashdata('test5'), NULL); + } + + /** + * Test the all_flashdata() function + */ + public function test_all_flashdata() + { + // Set a specific series of data for each driver + $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $this->session->cookie->set_flashdata($cdata); + $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); + $this->session->native->set_flashdata($ndata); + + // Simulate page reload and make sure all values are present + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($cdata, $this->session->cookie->all_flashdata()); + $this->assertEquals($ndata, $this->session->native->all_flashdata()); + } + + /** + * Test the set_tempdata() function + */ + public function test_set_tempdata() + { + // Set tempdata message for each driver - 1 second timeout + $cmsg = 'Some temp data'; + $this->session->cookie->set_tempdata('test6', $cmsg, 1); + $nmsg = 'Other temp data'; + $this->session->native->set_tempdata('test6', $nmsg, 1); + + // Simulate page reload and verify independent messages + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->tempdata('test6'), $cmsg); + $this->assertEquals($this->session->native->tempdata('test6'), $nmsg); + + // Wait 2 seconds, simulate page reload and verify message absence + sleep(2); + $this->session->cookie->reload(); + $this->session->native->reload(); + $this->assertEquals($this->session->cookie->tempdata('test6'), NULL); + $this->assertEquals($this->session->native->tempdata('test6'), NULL); + } + + /** + * Test the unset_tempdata() function + */ + public function test_unset_tempdata() + { + // Set tempdata message for each driver - 1 second timeout + $cmsg = 'My temp data'; + $this->session->cookie->set_tempdata('test7', $cmsg, 1); + $nmsg = 'Your temp data'; + $this->session->native->set_tempdata('test7', $nmsg, 1); + + // Verify independent messages + $this->assertEquals($this->session->cookie->tempdata('test7'), $cmsg); + $this->assertEquals($this->session->native->tempdata('test7'), $nmsg); + + // Unset data and verify message absence + $this->session->cookie->unset_tempdata('test7'); + $this->session->native->unset_tempdata('test7'); + $this->assertEquals($this->session->cookie->tempdata('test7'), NULL); + $this->assertEquals($this->session->native->tempdata('test7'), NULL); + } + + /** + * Test the sess_regenerate() function + */ + public function test_sess_regenerate() + { + // Get current session id, regenerate, and compare + // Cookie driver + $oldid = $this->session->cookie->userdata('session_id'); + $this->session->cookie->sess_regenerate(); + $newid = $this->session->cookie->userdata('session_id'); + $this->assertFalse($oldid === $newid); + + // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this + /*$oldid = session_id(); + $this->session->native->sess_regenerate(); + $oldid = session_id(); + $this->assertFalse($oldid === $newid);*/ + } + + /** + * Test the sess_destroy() function + */ + public function test_sess_destroy() + { + // Set a userdata message, destroy session, and verify absence + $msg = 'More test data'; + + // Cookie driver + $this->session->cookie->set_userdata('test8', $msg); + $this->assertEquals($this->session->cookie->userdata('test8'), $msg); + $this->session->cookie->sess_destroy(); + $this->assertEquals($this->session->cookie->userdata('test8'), NULL); + + // Native driver + $this->session->native->set_userdata('test8', $msg); + $this->assertEquals($this->session->native->userdata('test8'), $msg); + $this->session->native->sess_destroy(); + $this->assertEquals($this->session->native->userdata('test8'), NULL); + } +} + diff --git a/tests/mocks/autoloader.php b/tests/mocks/autoloader.php index be1c2220c..88d016bba 100644 --- a/tests/mocks/autoloader.php +++ b/tests/mocks/autoloader.php @@ -26,10 +26,14 @@ function autoload($class) 'Email', 'Encrypt', 'Form_validation', 'Ftp', 'Image_lib', 'Javascript', 'Log', 'Migration', 'Pagination', - 'Parser', 'Profiler', 'Session', - 'Table', 'Trackback', 'Typography', - 'Unit_test', 'Upload', 'User_agent', - 'Xmlrpc', 'Zip', + 'Parser', 'Profiler', 'Table', + 'Trackback', 'Typography', 'Unit_test', + 'Upload', 'User_agent', 'Xmlrpc', + 'Zip', + ); + + $ci_drivers = array( + 'Session', ); if (strpos($class, 'Mock_') === 0) @@ -52,6 +56,15 @@ function autoload($class) $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR; $class = ($subclass === 'Driver_Library') ? 'Driver' : $subclass; } + elseif (in_array($subclass, $ci_drivers)) + { + $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$subclass.DIRECTORY_SEPARATOR; + $class = $subclass; + } + elseif (in_array(($parent = strtok($subclass, '_')), $ci_drivers)) { + $dir = BASEPATH.'libraries'.DIRECTORY_SEPARATOR.$parent.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; + $class = $subclass; + } elseif (preg_match('/^CI_DB_(.+)_(driver|forge|result|utility)$/', $class, $m) && count($m) === 3) { $driver_path = BASEPATH.'database'.DIRECTORY_SEPARATOR.'drivers'.DIRECTORY_SEPARATOR; @@ -91,4 +104,4 @@ function autoload($class) } include_once($file); -} \ No newline at end of file +} diff --git a/tests/mocks/libraries/session.php b/tests/mocks/libraries/session.php new file mode 100644 index 000000000..9d6feee42 --- /dev/null +++ b/tests/mocks/libraries/session.php @@ -0,0 +1,43 @@ +_flashdata_sweep(); + $this->_flashdata_mark(); + $this->_tempdata_sweep(); + } +} + +/** + * Mock cookie driver to overload cookie setting + */ +class Mock_Libraries_Session_cookie extends CI_Session_cookie { + /** + * Overload _setcookie to manage $_COOKIE values, since actual cookies can't be set in unit testing + */ + protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, + $httponly = false) + { + if (empty($value) || $expire <= time()) { + // Clear cookie + unset($_COOKIE[$name]); + } + else { + // Set cookie + $_COOKIE[$name] = $value; + } + } +} + +/** + * Mock native driver (just for consistency in loading) + */ +class Mock_Libraries_Session_native extends CI_Session_native { } + -- cgit v1.2.3-24-g4f1b From 4153c928229ff174743b78472ae27138cd715efe Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 10:38:21 -0400 Subject: Coding standard cleanup and added userdata resync on sess_regenerate() --- tests/codeigniter/libraries/Session_test.php | 73 +++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index db7efb6b7..5d58a9e69 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -4,7 +4,11 @@ * Session driver library unit test */ class Session_test extends CI_TestCase { - protected $settings = array('use_cookies' => 0, 'use_only_cookies' => 0, 'cache_limiter' => false); + protected $settings = array( + 'use_cookies' => 0, + 'use_only_cookies' => 0, + 'cache_limiter' => false + ); protected $setting_vals = array(); protected $cookie_vals; protected $session; @@ -26,19 +30,40 @@ class Session_test extends CI_TestCase { // Establish necessary support classes $obj = new stdClass; - foreach (array('config' => 'cfg', 'load' => 'load', 'input' => 'in') as $name => $abbr) { + $classes = array( + 'config' => 'cfg', + 'load' => 'load', + 'input' => 'in' + ); + foreach ($classes as $name => $abbr) { $class = $this->ci_core_class($abbr); $obj->$name = new $class; } $this->ci_instance($obj); // Attach session instance locally - $config = array('sess_encrypt_cookie' => FALSE, 'sess_use_database' => FALSE, 'sess_table_name' => '', - 'sess_expiration' => 7200, 'sess_expire_on_close' => FALSE, 'sess_match_ip' => FALSE, - 'sess_match_useragent' => TRUE, 'sess_cookie_name' => 'ci_session', 'cookie_path' => '', - 'cookie_domain' => '', 'cookie_secure' => FALSE, 'cookie_httponly' => FALSE, 'sess_time_to_update' => 300, - 'time_reference' => 'local', 'cookie_prefix' => '', 'encryption_key' => 'foobar', - 'sess_valid_drivers' => array('Mock_Libraries_Session_native', 'Mock_Libraries_Session_cookie')); + $config = array( + 'sess_encrypt_cookie' => FALSE, + 'sess_use_database' => FALSE, + 'sess_table_name' => '', + 'sess_expiration' => 7200, + 'sess_expire_on_close' => FALSE, + 'sess_match_ip' => FALSE, + 'sess_match_useragent' => TRUE, + 'sess_cookie_name' => 'ci_session', + 'cookie_path' => '', + 'cookie_domain' => '', + 'cookie_secure' => FALSE, + 'cookie_httponly' => FALSE, + 'sess_time_to_update' => 300, + 'time_reference' => 'local', + 'cookie_prefix' => '', + 'encryption_key' => 'foobar', + 'sess_valid_drivers' => array( + 'Mock_Libraries_Session_native', + 'Mock_Libraries_Session_cookie' + ) + ); $this->session = new Mock_Libraries_Session($config); } @@ -96,9 +121,21 @@ class Session_test extends CI_TestCase { public function test_all_userdata() { // Set a specific series of data for each driver - $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); $this->session->cookie->set_userdata($cdata); - $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); $this->session->native->set_userdata($ndata); // Make sure all values are present @@ -202,9 +239,21 @@ class Session_test extends CI_TestCase { public function test_all_flashdata() { // Set a specific series of data for each driver - $cdata = array('one' => 'first', 'two' => 'second', 'three' => 'third', 'foo' => 'bar', 'bar' => 'baz'); + $cdata = array( + 'one' => 'first', + 'two' => 'second', + 'three' => 'third', + 'foo' => 'bar', + 'bar' => 'baz' + ); + $ndata = array( + 'one' => 'gold', + 'two' => 'silver', + 'three' => 'bronze', + 'foo' => 'baz', + 'bar' => 'foo' + ); $this->session->cookie->set_flashdata($cdata); - $ndata = array('one' => 'gold', 'two' => 'silver', 'three' => 'bronze', 'foo' => 'baz', 'bar' => 'foo'); $this->session->native->set_flashdata($ndata); // Simulate page reload and make sure all values are present -- cgit v1.2.3-24-g4f1b From 2642920e4781db091309ab97d0ff43c22e7c7e44 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 31 Jul 2012 10:55:07 -0400 Subject: Damn, missed files on last commit --- system/libraries/Session/Session.php | 16 ++++-- .../libraries/Session/drivers/Session_cookie.php | 61 +++++++++++++++++----- .../libraries/Session/drivers/Session_native.php | 16 ++++-- 3 files changed, 72 insertions(+), 21 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 68819a665..41539a598 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -64,7 +64,10 @@ class CI_Session extends CI_Driver_Library { // Get valid drivers list $CI =& get_instance(); - $this->valid_drivers = array('Session_native', 'Session_cookie'); + $this->valid_drivers = array( + 'Session_native', + 'Session_cookie' + ); $key = 'sess_valid_drivers'; $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); if ($drivers) @@ -116,7 +119,7 @@ class CI_Session extends CI_Driver_Library { */ public function load_driver($driver) { - // Save reference to most recently loaded driver as library default + // Save reference to most recently loaded driver as library default and sync userdata $this->current = parent::load_driver($driver); $this->userdata =& $this->current->get_userdata(); return $this->current; @@ -138,11 +141,13 @@ class CI_Session extends CI_Driver_Library { $child = str_replace($this->lib_name.'_', '', $driver); if (isset($this->$child)) { + // Make driver current and sync userdata $this->current = $this->$child; - $this->userdata =& $this->current->get_userdata(); + $this->userdata =& $this->current->get_userdata(); } else { + // Load new driver $this->load_driver($driver); } } @@ -167,8 +172,9 @@ class CI_Session extends CI_Driver_Library { */ public function sess_regenerate($destroy = false) { - // Just call regenerate on driver + // Call regenerate on driver and resync userdata $this->current->sess_regenerate($destroy); + $this->userdata =& $this->current->get_userdata(); } /** @@ -209,7 +215,7 @@ class CI_Session extends CI_Driver_Library { // if it contains flashdata, add it if (strpos($key, self::FLASHDATA_KEY.self::FLASHDATA_OLD) !== FALSE) { - $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); + $key = str_replace(self::FLASHDATA_KEY.self::FLASHDATA_OLD, '', $key); $out[$key] = $val; } } diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 19ccd417d..8ac92e432 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -72,7 +72,7 @@ class CI_Session_cookie extends CI_Session_driver { * * @var bool */ - public $sess_expire_on_close = FALSE; + public $sess_expire_on_close = FALSE; /** * Whether to match session on ip address @@ -86,7 +86,7 @@ class CI_Session_cookie extends CI_Session_driver { * * @var bool */ - public $sess_match_useragent = TRUE; + public $sess_match_useragent = TRUE; /** * Name of session cookie @@ -107,7 +107,7 @@ class CI_Session_cookie extends CI_Session_driver { * * @var string */ - public $cookie_path = ''; + public $cookie_path = ''; /** * Session cookie domain @@ -156,7 +156,7 @@ class CI_Session_cookie extends CI_Session_driver { * * @var array */ - public $userdata = array(); + public $userdata = array(); /** * Reference to CodeIgniter instance @@ -185,10 +185,25 @@ class CI_Session_cookie extends CI_Session_driver { // Set all the session preferences, which can either be set // manually via the $params array or via the config file - foreach (array('sess_encrypt_cookie', 'sess_use_database', 'sess_table_name', 'sess_expiration', - 'sess_expire_on_close', 'sess_match_ip', 'sess_match_useragent', 'sess_cookie_name', 'cookie_path', - 'cookie_domain', 'cookie_secure', 'cookie_httponly', 'sess_time_to_update', 'time_reference', 'cookie_prefix', - 'encryption_key') as $key) + $prefs = array( + 'sess_encrypt_cookie', + 'sess_use_database', + 'sess_table_name', + 'sess_expiration', + 'sess_expire_on_close', + 'sess_match_ip', + 'sess_match_useragent', + 'sess_cookie_name', + 'cookie_path', + 'cookie_domain', + 'cookie_secure', + 'cookie_httponly', + 'sess_time_to_update', + 'time_reference', + 'cookie_prefix', + 'encryption_key' + ); + foreach ($prefs as $key) { $this->$key = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : $this->CI->config->item($key); @@ -265,7 +280,13 @@ class CI_Session_cookie extends CI_Session_driver { // Before continuing, we need to determine if there is any custom data to deal with. // Let's determine this by removing the default indexes to see if there's anything left in the array // and set the session data while we're at it - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) + $defaults = array( + 'session_id', + 'ip_address', + 'user_agent', + 'last_activity' + ); + foreach ($defaults as $val) { unset($custom_userdata[$val]); $cookie_userdata[$val] = $this->userdata[$val]; @@ -285,8 +306,10 @@ class CI_Session_cookie extends CI_Session_driver { // Run the update query $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->update($this->sess_table_name, - array('last_activity' => $this->userdata['last_activity'], 'user_data' => $custom_userdata)); + $this->CI->db->update($this->sess_table_name, array( + 'last_activity' => $this->userdata['last_activity'], + 'user_data' => $custom_userdata + )); // Write the cookie. Notice that we manually pass the cookie data array to the // _set_cookie() function. Normally that function will store $this->userdata, but @@ -535,7 +558,13 @@ class CI_Session_cookie extends CI_Session_driver { { // set cookie explicitly to only have our session data $cookie_data = array(); - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) + $defaults = array( + 'session_id', + 'ip_address', + 'user_agent', + 'last_activity' + ); + foreach ($defaults as $val) { $cookie_data[$val] = $this->userdata[$val]; } @@ -570,7 +599,13 @@ class CI_Session_cookie extends CI_Session_driver { { // set cookie explicitly to only have our session data $cookie_data = array(); - foreach (array('session_id','ip_address','user_agent','last_activity') as $val) + $defaults = array( + 'session_id', + 'ip_address', + 'user_agent', + 'last_activity' + ); + foreach ($defaults as $val) { $cookie_data[$val] = $this->userdata[$val]; } diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 27db942eb..356deb4dc 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -36,10 +36,20 @@ class CI_Session_native extends CI_Session_driver { // Get config parameters $config = array(); $CI =& get_instance(); - foreach (array('sess_cookie_name', 'sess_expire_on_close', 'sess_expiration', 'sess_match_ip', - 'sess_match_useragent', 'cookie_prefix', 'cookie_path', 'cookie_domain') as $key) + $prefs = array( + 'sess_cookie_name', + 'sess_expire_on_close', + 'sess_expiration', + 'sess_match_ip', + 'sess_match_useragent', + 'cookie_prefix', + 'cookie_path', + 'cookie_domain' + ); + foreach ($prefs as $key) { - $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : $CI->config->item($key); + $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : + $CI->config->item($key); } // Set session name, if specified -- cgit v1.2.3-24-g4f1b From 0e0c37bc3b8e46d9ecc89fd5591e6b258ebd8b74 Mon Sep 17 00:00:00 2001 From: Francesco Negri Date: Sat, 4 Aug 2012 14:16:50 +0300 Subject: Logging should obey error_reporting() setting If the php error level is not included in the current error_reporting() setting, we should not log it. Also, the log_threshold check is redundant, it's already taken care of by the write_log() method. --- system/core/Common.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 57374b07d..cb99d0505 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -524,21 +524,20 @@ if ( ! function_exists('_exception_handler')) { $_error =& load_class('Exceptions', 'core'); - // Should we display the error? We'll get the current error_reporting + // Should we ignore the error? We'll get the current error_reporting // level and add its bits with the severity bits to find out. - // And respect display_errors - if (($severity & error_reporting()) === $severity && (bool) ini_get('display_errors') === TRUE) + if (($severity & error_reporting()) !== $severity) + { + return; + } + + // Should we display the error? + if ((bool) ini_get('display_errors') === TRUE) { $_error->show_php_error($severity, $message, $filepath, $line); } - // Should we log the error? No? We're done... - if (config_item('log_threshold') === 0) - { - return; - } - - $_error->log_exception($severity, $message, $filepath, $line); + $_error->log_exception($severity, $message, $filepath, $line); } } -- cgit v1.2.3-24-g4f1b From 312bdc5e2160784c7fdd0f38c6d417a9eb5babe0 Mon Sep 17 00:00:00 2001 From: Francesco Negri Date: Sat, 4 Aug 2012 07:32:19 -0400 Subject: fixed whitespace --- system/core/Common.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index cb99d0505..32c8bd68d 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -527,17 +527,17 @@ if ( ! function_exists('_exception_handler')) // Should we ignore the error? We'll get the current error_reporting // level and add its bits with the severity bits to find out. if (($severity & error_reporting()) !== $severity) - { - return; - } - - // Should we display the error? - if ((bool) ini_get('display_errors') === TRUE) + { + return; + } + + // Should we display the error? + if ((bool) ini_get('display_errors') === TRUE) { $_error->show_php_error($severity, $message, $filepath, $line); } - $_error->log_exception($severity, $message, $filepath, $line); + $_error->log_exception($severity, $message, $filepath, $line); } } -- cgit v1.2.3-24-g4f1b From f79afb57b7f7bac62a79638f195560739e4a80ef Mon Sep 17 00:00:00 2001 From: dchill42 Date: Wed, 8 Aug 2012 12:03:46 -0400 Subject: Added session_id to userdata and applied sess_time_to_update --- system/libraries/Session/drivers/Session_native.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 356deb4dc..04c985574 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -42,6 +42,7 @@ class CI_Session_native extends CI_Session_driver { 'sess_expiration', 'sess_match_ip', 'sess_match_useragent', + 'sess_time_to_update', 'cookie_prefix', 'cookie_path', 'cookie_domain' @@ -117,6 +118,14 @@ class CI_Session_native extends CI_Session_driver { session_start(); } + // Check for update time + if ($config['sess_time_to_update'] && isset($_SESSION['last_activity']) && + ($_SESSION['last_activity'] + $config['sess_time_to_update']) < $now) + { + // Regenerate ID, but don't destroy session + $this->sess_regenerate(FALSE); + } + // Set activity time $_SESSION['last_activity'] = $now; @@ -131,6 +140,9 @@ class CI_Session_native extends CI_Session_driver { // Store user agent string $_SESSION['user_agent'] = trim(substr($CI->input->user_agent(), 0, 50)); } + + // Make session ID available + $_SESSION['session_id'] = session_id(); } /** @@ -178,6 +190,7 @@ class CI_Session_native extends CI_Session_driver { { // Just regenerate id, passing destroy flag session_regenerate_id($destroy); + $_SESSION['session_id'] = session_id(); } /** -- cgit v1.2.3-24-g4f1b From 5628ba0efca7a631012fef91e259b92d7d807af1 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Wed, 8 Aug 2012 12:05:45 -0400 Subject: Relocated driver base class inclusion so drivers can be loaded with library() --- system/core/Loader.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/system/core/Loader.php b/system/core/Loader.php index ea81c6f26..a62cf06f5 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -409,8 +409,8 @@ class CI_Loader { * 1. The name of the "view" file to be included. * 2. An associative array of data to be extracted for use in the view. * 3. TRUE/FALSE - whether to return the data or load it. In - * some cases it's advantageous to be able to return data so that - * a developer can process it in some way. + * some cases it's advantageous to be able to return data so that + * a developer can process it in some way. * * @param string * @param array @@ -636,12 +636,6 @@ class CI_Loader { return FALSE; } - if ( ! class_exists('CI_Driver_Library')) - { - // we aren't instantiating an object here, that'll be done by the Library itself - require BASEPATH.'libraries/Driver.php'; - } - if ($library === '') { return FALSE; @@ -837,10 +831,10 @@ class CI_Loader { * We buffer the output for two reasons: * 1. Speed. You get a significant speed boost. * 2. So that the final rendered template can be post-processed by - * the output class. Why do we need post processing? For one thing, - * in order to show the elapsed page load time. Unless we can - * intercept the content right before it's sent to the browser and - * then stop the timer it won't be accurate. + * the output class. Why do we need post processing? For one thing, + * in order to show the elapsed page load time. Unless we can + * intercept the content right before it's sent to the browser and + * then stop the timer it won't be accurate. */ ob_start(); @@ -915,6 +909,13 @@ class CI_Loader { // Get the filename from the path $class = substr($class, $last_slash); + + // Check for match and driver base class + if (strtolower($subdir) == strtolower($class) && ! class_exists('CI_Driver_Library')) + { + // We aren't instantiating an object here, just making the base class available + require BASEPATH.'libraries/Driver.php'; + } } // We'll test for both lowercase and capitalized versions of the file name @@ -996,7 +997,6 @@ class CI_Loader { $this->_ci_loaded_files[] = $filepath; return $this->_ci_init_class($class, '', $params, $object_name); } - } // END FOREACH // One last attempt. Maybe the library is in a subdirectory, but it wasn't specified? -- cgit v1.2.3-24-g4f1b From 0e88408d0965ee539d9af3ff7eca5415d3276c74 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sat, 11 Aug 2012 20:10:17 -0400 Subject: Updated comments about default driver --- system/libraries/Session/Session.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 41539a598..97eab803f 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -18,8 +18,8 @@ * CI_Session Class * * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms. - * By default, the native PHP session driver will load, but the 'sess_driver' config/param item (see above) can be - * used to specify the 'cookie' driver, or any other you might create. + * By default, the cookie session driver will load, but the 'sess_driver' config/param item (see above) can be + * used to specify the 'native' driver, or any other you might create. * Once loaded, this driver setup is a drop-in replacement for the former CI_Session library, taking its place as the * 'session' member of the global controller framework (e.g.: $CI->session or $this->session). * In keeping with the CI_Driver methodology, multiple drivers may be loaded, although this might be a bit confusing. -- cgit v1.2.3-24-g4f1b From 3169f26fe6b5e23d5ab5d791143d1dd51d78f80d Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sat, 11 Aug 2012 20:12:05 -0400 Subject: Updated Loader and Session documentation --- user_guide_src/source/index.rst | 3 +- user_guide_src/source/libraries/loader.rst | 71 +++++- user_guide_src/source/libraries/sessions.rst | 338 ++++++++++++++++++++------- 3 files changed, 328 insertions(+), 84 deletions(-) diff --git a/user_guide_src/source/index.rst b/user_guide_src/source/index.rst index e42425bab..35089703f 100644 --- a/user_guide_src/source/index.rst +++ b/user_guide_src/source/index.rst @@ -80,6 +80,7 @@ Driver Reference - :doc:`libraries/caching` - :doc:`database/index` - :doc:`libraries/javascript` +- :doc:`libraries/sessions` **************** Helper Reference @@ -119,4 +120,4 @@ Contributing to CodeIgniter documentation/index tutorial/index general/quick_reference - general/credits \ No newline at end of file + general/credits diff --git a/user_guide_src/source/libraries/loader.rst b/user_guide_src/source/libraries/loader.rst index aadf9740a..5a17629d2 100644 --- a/user_guide_src/source/libraries/loader.rst +++ b/user_guide_src/source/libraries/loader.rst @@ -4,6 +4,7 @@ Loader Class Loader, as the name suggests, is used to load elements. These elements can be libraries (classes) :doc:`View files <../general/views>`, +:doc:`Drivers <../general/drivers>`, :doc:`Helpers <../general/helpers>`, :doc:`Models <../general/models>`, or your own files. @@ -74,6 +75,70 @@ Assigning a Library to a different object name If the third (optional) parameter is blank, the library will usually be assigned to an object with the same name as the library. For example, if +the library is named Calendar, it will be assigned to a variable named +$this->calendar. + +If you prefer to set your own class names you can pass its value to the +third parameter:: + + $this->load->library('calendar', '', 'my_calendar'); + + // Session class is now accessed using: + + $this->my_calendar + +Please take note, when multiple libraries are supplied in an array for +the first parameter, this parameter is discarded. + +$this->load->driver('parent_name', $config, 'object name') +=========================================================== + +This function is used to load driver libraries. Where parent_name is the +name of the parent class you want to load. + +As an example, if you would like to use sessions with CodeIgniter, the first +step is to load the session driver within your controller:: + + $this->load->driver('session'); + +Once loaded, the library will be ready for use, using +$this->session->*some_function*(). + +Driver files must be stored in a subdirectory within the main +"libraries" folder, or within your personal application/libraries +folder. The subdirectory must match the parent class name. Read the +:doc:`Drivers <../general/drivers>` description for details. + +Additionally, multiple driver libraries can be loaded at the same time by +passing an array of drivers to the load function. + +:: + + $this->load->driver(array('session', 'cache')); + +Setting options +--------------- + +The second (optional) parameter allows you to optionally pass +configuration settings. You will typically pass these as an array:: + + $config = array ( + 'sess_driver' => 'cookie', + 'sess_encrypt_cookie' => true, + 'encryption_key' => 'mysecretkey' + ); + + $this->load->driver('session', $config); + +Config options can usually also be set via a config file. Each library +is explained in detail in its own page, so please read the information +regarding each one you would like to use. + +Assigning a Driver to a different object name +---------------------------------------------- + +If the third (optional) parameter is blank, the library will be assigned +to an object with the same name as the parent class. For example, if the library is named Session, it will be assigned to a variable named $this->session. @@ -86,8 +151,8 @@ third parameter:: $this->my_session -Please take note, when multiple libraries are supplied in an array for -the first parameter, this parameter is discarded. +.. note:: Driver libraries may also be loaded with the library() method, + but it is faster to use driver() $this->load->view('file_name', $data, true/false) ================================================== @@ -281,4 +346,4 @@ calling add_package_path(). // Again without the second parameter: $this->load->add_package_path(APPPATH.'my_app', TRUE); $this->load->view('my_app_index'); // Loads - $this->load->view('welcome_message'); // Loads \ No newline at end of file + $this->load->view('welcome_message'); // Loads diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 5400524a9..7a27a8f34 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -1,29 +1,19 @@ -############# -Session Class -############# +############## +Session Driver +############## The Session class permits you maintain a user's "state" and track their -activity while they browse your site. The Session class stores session -information for each user as serialized (and optionally encrypted) data -in a cookie. It can also store the session data in a database table for -added security, as this permits the session ID in the user's cookie to -be matched against the stored session ID. By default only the cookie is -saved. If you choose to use the database option you'll need to create -the session table as indicated below. - -.. note:: The Session class does **not** utilize native PHP sessions. It - generates its own session data, offering more flexibility for - developers. - -.. note:: Even if you are not using encrypted sessions, you must set - an :doc:`encryption key <./encryption>` in your config file which is used - to aid in preventing session data manipulation. +activity while they browse your site. CodeIgniter offers two default +session drivers: the classic `Cookie Driver`_, and the `Native Driver`_, +which supports usage of the native PHP Session mechanism. In addition, +you may create your own `Custom Drivers`_ to store session data however +you wish, while still taking advantage of the features of the Session class. Initializing a Session ====================== Sessions will typically run globally with each page load, so the session -class must either be :doc:`initialized <../general/libraries>` in your +class must either be :doc:`initialized <../general/drivers>` in your :doc:`controller <../general/controllers>` constructors, or it can be :doc:`auto-loaded <../general/autoloader>` by the system. For the most part the session class will run unattended in the background, so simply @@ -31,22 +21,25 @@ initializing the class will cause it to read, create, and update sessions. To initialize the Session class manually in your controller constructor, -use the $this->load->library function:: +use the $this->load->driver function:: - $this->load->library('session'); + $this->load->driver('session'); Once loaded, the Sessions library object will be available using: $this->session +.. note:: For backward compatibility, the Session class may stil be loaded + using the $this->load->library function, but converting your applications + to use $this->load->driver is strongly recommended. + How do Sessions work? ===================== When a page is loaded, the session class will check to see if valid -session data exists in the user's session cookie. If sessions data does -**not** exist (or if it has expired) a new session will be created and -saved in the cookie. If a session does exist, its information will be -updated and the cookie will be updated. With each update, the -session_id will be regenerated. +session data exists in the user's session. If sessions data does **not** +exist (or if it has expired) a new session will be created and saved. +If a session does exist, its information will be updated. With each update, +the session_id will be regenerated. It's important for you to understand that once initialized, the Session class runs automatically. There is nothing you need to do to cause the @@ -79,19 +72,12 @@ prototype:: 'last_activity' => timestamp ) -If you have the encryption option enabled, the serialized array will be -encrypted before being stored in the cookie, making the data highly -secure and impervious to being read or altered by someone. More info -regarding encryption can be :doc:`found here `, although -the Session class will take care of initializing and encrypting the data -automatically. - -Note: Session cookies are only updated every five minutes by default to -reduce processor load. If you repeatedly reload a page you'll notice -that the "last activity" time only updates if five minutes or more has -passed since the last time the cookie was written. This time is -configurable by changing the $config['sess_time_to_update'] line in -your system/config/config.php file. +.. note:: Sessions are only updated every five minutes by default to + reduce processor load. If you repeatedly reload a page you'll notice + that the "last activity" time only updates if five minutes or more has + passed since the last time the cookie was written. This time is + configurable by changing the $config['sess_time_to_update'] line in + your system/config/config.php file. Retrieving Session Data ======================= @@ -106,7 +92,7 @@ fetch. For example, to fetch the session ID you will do this:: $session_id = $this->session->userdata('session_id'); -.. note:: The function returns FALSE (boolean) if the item you are +.. note:: The function returns NULL if the item you are trying to access does not exist. Adding Custom Session Data @@ -117,7 +103,7 @@ to it and it will be stored in the user's cookie. Why would you want to do this? Here's one example: Let's say a particular user logs into your site. Once authenticated, you -could add their username and email address to the session cookie, making +could add their username and email address to the session, making that data globally available to you without having to run a database query when you need it. @@ -144,11 +130,11 @@ supports this syntax. $this->session->set_userdata('some_name', 'some_value'); +If you want to verify that a userdata value exists, call has_userdata(). -.. note:: Cookies can only hold 4KB of data, so be careful not to exceed - the capacity. The encryption process in particular produces a longer - data string than the original so keep careful track of how much data you - are storing. +:: + + $this->session->has_userdata('some_name'); Retrieving All Session Data =========================== @@ -195,8 +181,8 @@ available for the next server request, and are then automatically cleared. These can be very useful, and are typically used for informational or status messages (for example: "record 2 deleted"). -Note: Flash variables are prefaced with "flash\_" so avoid this prefix -in your own session names. +.. note:: Flash variables are prefaced with "flash\_" so avoid this prefix + in your own session names. To add flashdata:: @@ -222,9 +208,162 @@ additional request, you can do so using the keep_flashdata() function. $this->session->keep_flashdata('item'); +Tempdata +======== + +CodeIgniter also supports "tempdata", or session data with a specific +expiration time. After the value expires, or the session expires or is +deleted, the value is automatically removed. + +To add tempdata:: + + $expire = 300; // Expire in 5 minutes + + $this->session->set_tempdata('item', 'value', $expire); + +You can also pass an array to set_tempdata():: + + $tempdata = array('newuser' => TRUE, 'message' => 'Thanks for joining!'); + + $this->session->set_tempdata($tempdata, '', $expire); + +.. note:: If the expiration is omitted or set to 0, the default expiration of + 5 minutes will be used. + +To read a tempdata variable:: + + $this->session->tempdata('item'); + +If you need to remove a tempdata value before it expires, +use unset_tempdata():: + + $this->session->unset_tempdata('item'); + +Destroying a Session +==================== + +To clear the current session:: + + $this->session->sess_destroy(); + +.. note:: This function should be the last one called, and even flash + variables will no longer be available. If you only want some items + destroyed and not all, use unset_userdata(). + +Session Preferences +=================== + +You'll find the following Session related preferences in your +application/config/config.php file: + +=========================== =============== =========================== ========================================================================== +Preference Default Options Description +=========================== =============== =========================== ========================================================================== +**sess_driver** cookie cookie/native/*custom* The initial session driver to load. +**sess_valid_drivers** cookie, native None Additional valid drivers which may be loaded. +**sess_cookie_name** ci_session None The name you want the session cookie saved as (data for Cookie driver or + session ID for Native driver). +**sess_expiration** 7200 None The number of seconds you would like the session to last. The default + value is 2 hours (7200 seconds). If you would like a non-expiring + session set the value to zero: 0 +**sess_expire_on_close** FALSE TRUE/FALSE (boolean) Whether to cause the session to expire automatically when the browser + window is closed. +**sess_encrypt_cookie** FALSE TRUE/FALSE (boolean) Whether to encrypt the session data (Cookie driver only). +**sess_use_database** FALSE TRUE/FALSE (boolean) Whether to save the session data to a database. You must create the + table before enabling this option (Cookie driver only). +**sess_table_name** ci_sessions Any valid SQL table name The name of the session database table (Cookie driver only). +**sess_time_to_update** 300 Time in seconds This options controls how often the session class will regenerate itself + and create a new session id. +**sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to match the user's IP address when reading the session data. + Note that some ISPs dynamically changes the IP, so if you want a + non-expiring session you will likely set this to FALSE. +**sess_match_useragent** TRUE TRUE/FALSE (boolean) Whether to match the User Agent when reading the session data. +=========================== =============== =========================== ========================================================================== + +In addition to the values above, the cookie and native drivers apply the +following configuration values shared by the :doc:`Input ` and +:doc:`Security ` classes: + +=========================== =============== ========================================================================== +Preference Default Description +=========================== =============== ========================================================================== +**cookie_prefix** '' Set a cookie name prefix in order to avoid name collisions +**cookie_domain** '' The domain for which the session is applicable +**cookie_path** / The path to which the session is applicable +=========================== =============== ========================================================================== + +Session Drivers +=============== + +By default, the `Cookie Driver`_ is loaded when a session is initialized. +However, any valid driver may be selected with the $config['sess_driver'] +line in your config.php file. + +The session driver library comes with the cookie and native drivers +installed, and `Custom Drivers`_ may also be installed by the user. + +Typically, only one driver will be used at a time, but CodeIgniter does +support loading multiple drivers. If a specific valid driver is called, it +will be automatically loaded. Or, an additional driver may be explicitly +loaded by calling load_driver():: + + $this->session->load_driver('native'); + +The Session library keeps track of the most recently selected driver to call +for driver methods. Normally, session class methods are called directly on +the parent class, as illustrated above. However, any methods called through +a specific driver will select that driver before invoking the parent method. + +So, alternation between multiple drivers can be achieved by specifying which +driver to use for each call:: + + $this->session->native->set_userdata('foo', 'bar'); + + $this->session->cookie->userdata('foo'); + + $this->session->native->unset_userdata('foo'); + +Notice in the previous example that the *native* userdata value 'foo' +would be set to 'bar', which would NOT be returned by the call for +the *cookie* userdata 'foo', nor would the *cookie* value be unset by +the call to unset the *native* 'foo' value. The drivers maintain independent +sets of values, regardless of key names. + +A specific driver may also be explicitly selected for use by pursuant +methods with the select_driver() call:: + + $this->session->select_driver('native'); + + $this->session->userdata('item'); // Uses the native driver + +Cookie Driver +------------- + +The Cookie driver stores session information for each user as serialized +(and optionally encrypted) data in a cookie. It can also store the session +data in a database table for added security, as this permits the session ID +in the user's cookie to be matched against the stored session ID. By default +only the cookie is saved. If you choose to use the database option you'll +need to create the session table as indicated below. + +If you have the encryption option enabled, the serialized array will be +encrypted before being stored in the cookie, making the data highly +secure and impervious to being read or altered by someone. More info +regarding encryption can be :doc:`found here `, although +the Session class will take care of initializing and encrypting the data +automatically. + +.. note:: Even if you are not using encrypted sessions, you must set + an :doc:`encryption key <./encryption>` in your config file which is used + to aid in preventing session data manipulation. + +.. note:: Cookies can only hold 4KB of data, so be careful not to exceed + the capacity. The encryption process in particular produces a longer + data string than the original so keep careful track of how much data you + are storing. Saving Session Data to a Database -================================= +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ While the session data array stored in the user's cookie contains a Session ID, unless you store session data in a database there is no way @@ -267,44 +406,83 @@ session class:: $config['sess_table_name'] = 'ci_sessions'; -.. note:: The Session class has built-in garbage collection which clears +.. note:: The Cookie driver has built-in garbage collection which clears out expired sessions so you do not need to write your own routine to do it. -Destroying a Session -==================== +Native Driver +------------- -To clear the current session:: +The Native driver relies on native PHP sessions to store data in the +$_SESSION superglobal array. All stored values continue to be available +through $_SESSION, but flash- and temp- data items carry special prefixes. - $this->session->sess_destroy(); +Custom Drivers +-------------- -.. note:: This function should be the last one called, and even flash - variables will no longer be available. If you only want some items - destroyed and not all, use unset_userdata(). +You may also :doc:`create your own <../general/creating_drivers>` custom +session drivers. A session driver basically manages an array of name/value +pairs with some sort of storage mechanism. -Session Preferences -=================== +To make a new driver, extend CI_Session_driver. Overload the initialize +method and read or create session data. Then implement a save handler to +write changed data to storage (sess_save), a destroy handler to remove +deleted data (sess_destroy), a regenerate handler to make a new session ID, +and an access handler to expose the data (get_userdata). Your initial class +might look like:: -You'll find the following Session related preferences in your -application/config/config.php file: + class CI_Session_custom extends CI_Session_driver { + protected function initialize() + { + // Read existing session data or create a new one + } + + public function sess_save() + { + // Save current data to storage + } + + public function sess_destroy() + { + // Destroy the current session and clean up storage + } + + public function sess_regenerate() + { + // Create new session ID + } + + public function &get_userdata() + { + // Return a reference to your userdata array + } + } + +Notice that get_userdata() returns a reference so the parent library is +accessing the same array the driver object is using. This saves memory +and avoids synchronization issues during usage. + +Put your driver in the libraries/Session/drivers folder anywhere in your +package paths. This includes the application directory, the system directory, +or any path you add with $CI->load->add_package_path(). Your driver must be +named CI_Session_, and your filename must be Session_.php, +preferably also capitalized, such as:: + + CI_Session_foo in libraries/Session/drivers/Session_foo.php + +Then specify the driver by setting 'sess_driver' in your config.php file or as a +parameter when loading the CI_Session object:: + + $config['sess_driver'] = 'foo'; + +OR:: + + $CI->load->driver('session', array('sess_driver' => 'foo')); + +The driver specified by 'sess_driver' is automatically included as a valid +driver. However, if you want to make a custom driver available as an option +without making it the initially loaded driver, set 'sess_valid_drivers' in +your config.php file to an array including your driver name:: + + $config['sess_valid_drivers'] = array('sess_driver'); -=========================== =============== =========================== ========================================================================== -Preference Default Options Description -=========================== =============== =========================== ========================================================================== -**sess_cookie_name** ci_session None The name you want the session cookie saved as. -**sess_expiration** 7200 None The number of seconds you would like the session to last. The default - value is 2 hours (7200 seconds). If you would like a non-expiring - session set the value to zero: 0 -**sess_expire_on_close** FALSE TRUE/FALSE (boolean) Whether to cause the session to expire automatically when the browser - window is closed. -**sess_encrypt_cookie** FALSE TRUE/FALSE (boolean) Whether to encrypt the session data. -**sess_use_database** FALSE TRUE/FALSE (boolean) Whether to save the session data to a database. You must create the - table before enabling this option. -**sess_table_name** ci_sessions Any valid SQL table name The name of the session database table. -**sess_time_to_update** 300 Time in seconds This options controls how often the session class will regenerate itself - and create a new session id. -**sess_match_ip** FALSE TRUE/FALSE (boolean) Whether to match the user's IP address when reading the session data. - Note that some ISPs dynamically changes the IP, so if you want a - non-expiring session you will likely set this to FALSE. -**sess_match_useragent** TRUE TRUE/FALSE (boolean) Whether to match the User Agent when reading the session data. -=========================== =============== =========================== ========================================================================== \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 19d0f56d53997dba23a736295aa2a67fbc5ad52f Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Sat, 11 Aug 2012 19:53:59 -0500 Subject: Bug fix #1695 - change Nintendo mobile user agents to be more specific. Signed-off-by: Eric Roberts --- application/config/user_agents.php | 6 +++--- user_guide_src/source/changelog.rst | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/application/config/user_agents.php b/application/config/user_agents.php index 9befddc99..78e4c8c7d 100644 --- a/application/config/user_agents.php +++ b/application/config/user_agents.php @@ -157,10 +157,10 @@ $mobiles = array( 'spv' => 'SPV', 'zte' => 'ZTE', 'sendo' => 'Sendo', - 'dsi' => 'Nintendo DSi', - 'ds' => 'Nintendo DS', + 'nintendo dsi' => 'Nintendo DSi', + 'nintendo ds' => 'Nintendo DS', + 'nintendo 3ds' => 'Nintendo 3DS', 'wii' => 'Nintendo Wii', - '3ds' => 'Nintendo 3DS', 'open web' => 'Open Web', 'openweb' => 'OpenWeb', diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 03df6e3a8..3f6906716 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -320,6 +320,7 @@ Bug fixes for 3.0 - Fixed a bug (#1613) - :doc:`Form Helper ` functions ``form_multiselect()``, ``form_dropdown()`` didn't properly handle empty array option groups. - Fixed a bug (#1605) - :doc:`Pagination Library ` produced incorrect *previous* and *next* link values. - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. +- Fixed a bug (#1695) - IE8 occasionally registered as mobile browser, due to Nintedo DS user agent's "ds" key. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From b3816b794592873a4e98187e66745544b463e933 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 13 Aug 2012 09:47:58 -0400 Subject: Minor doc fixes --- user_guide_src/source/libraries/loader.rst | 2 +- user_guide_src/source/libraries/sessions.rst | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/libraries/loader.rst b/user_guide_src/source/libraries/loader.rst index 5a17629d2..33c1bafec 100644 --- a/user_guide_src/source/libraries/loader.rst +++ b/user_guide_src/source/libraries/loader.rst @@ -83,7 +83,7 @@ third parameter:: $this->load->library('calendar', '', 'my_calendar'); - // Session class is now accessed using: + // Calendar class is now accessed using: $this->my_calendar diff --git a/user_guide_src/source/libraries/sessions.rst b/user_guide_src/source/libraries/sessions.rst index 7a27a8f34..dd9e8cbb4 100644 --- a/user_guide_src/source/libraries/sessions.rst +++ b/user_guide_src/source/libraries/sessions.rst @@ -424,12 +424,12 @@ You may also :doc:`create your own <../general/creating_drivers>` custom session drivers. A session driver basically manages an array of name/value pairs with some sort of storage mechanism. -To make a new driver, extend CI_Session_driver. Overload the initialize +To make a new driver, extend CI_Session_driver. Overload the initialize() method and read or create session data. Then implement a save handler to write changed data to storage (sess_save), a destroy handler to remove -deleted data (sess_destroy), a regenerate handler to make a new session ID, -and an access handler to expose the data (get_userdata). Your initial class -might look like:: +deleted data (sess_destroy), a regenerate handler to make a new session ID +(sess_regenerate), and an access handler to expose the data (get_userdata). +Your initial class might look like:: class CI_Session_custom extends CI_Session_driver { protected function initialize() -- cgit v1.2.3-24-g4f1b From b5ecafe0df2c4a2e81e27eab2d06af61d1eefa9e Mon Sep 17 00:00:00 2001 From: Ollie Rattue Date: Wed, 15 Aug 2012 00:11:43 -0500 Subject: Working mime types for xls and xlsx file extensions --- application/config/mimes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/config/mimes.php b/application/config/mimes.php index a239bb254..6cc1ae9ef 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -56,7 +56,7 @@ return array( 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', - 'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'), + 'xls' => array('application/vnd.ms-excel', 'application/vnd.ms-excel [official]', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'wbxml' => 'application/wbxml', @@ -124,7 +124,7 @@ return array( 'movie' => 'video/x-sgi-movie', 'doc' => array('application/msword', 'application/vnd.ms-office'), 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'), - 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'), + 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword'), 'word' => array('application/msword', 'application/octet-stream'), 'xl' => 'application/excel', 'eml' => 'message/rfc822', -- cgit v1.2.3-24-g4f1b From 670182374d05e05f308d8e30607f5538f322d370 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Aug 2012 11:11:32 +0300 Subject: Add changelog entry for pull #1601 --- user_guide_src/source/changelog.rst | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 03df6e3a8..827b1f090 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -102,12 +102,13 @@ Release Date: Not Released - Replaced the _error_message() and _error_number() methods with error(), that returns an array containing the last database error code and message. - Improved version() implementation so that drivers that have a native function to get the version number don't have to be defined in the core DB_driver class. - Improved support of the PostgreSQL driver, including: - - pg_version() is now used to get the database version number, when possible. - - Added db_set_charset() support. - - Added support for optimize_table() in :doc:`Database Utilities ` (rebuilds table indexes). - - Added boolean data type support in escape(). - - Added update_batch() support. - - Removed limit() and order_by() support for UPDATE and DELETE queries in as PostgreSQL does not support those features. + - ``pg_version()`` is now used to get the database version number, when possible. + - Added ``db_set_charset()`` support. + - Added support for ``optimize_table()`` in :doc:`Database Utilities ` (rebuilds table indexes). + - Added boolean data type support in ``escape()``. + - Added ``update_batch()`` support. + - Removed ``limit()`` and ``order_by()`` support for UPDATE and DELETE queries as PostgreSQL does not support those features. + - Added a work-around for dead persistent connections to be re-created after a database restart. - Added a constructor to the DB_result class and moved all driver-specific properties and logic out of the base DB_driver class to allow better abstraction. - Removed protect_identifiers() and renamed internal method _protect_identifiers() to it instead - it was just an alias. - Renamed internal method _escape_identifiers() to escape_identifiers(). -- cgit v1.2.3-24-g4f1b From 6a64f856ae09fb14460cf09544a5fe9f2f463fea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 15 Aug 2012 11:16:47 +0300 Subject: Fix issue #1712 --- system/helpers/html_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 9843e804e..2372e8174 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -215,7 +215,7 @@ if ( ! function_exists('img')) } } - return $img._stringify_attributes($attributes).'/>'; + return $img._stringify_attributes($attributes).' />'; } } -- cgit v1.2.3-24-g4f1b From 8b4869abe5be546d64a516e42d0559d3bdc1ed53 Mon Sep 17 00:00:00 2001 From: Ollie Rattue Date: Wed, 15 Aug 2012 11:43:52 -0500 Subject: Removed invalid 'application/vnd.ms-excel [official]' mime type from xls --- application/config/mimes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/mimes.php b/application/config/mimes.php index 6cc1ae9ef..1917b11de 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -56,7 +56,7 @@ return array( 'smi' => 'application/smil', 'smil' => 'application/smil', 'mif' => 'application/vnd.mif', - 'xls' => array('application/vnd.ms-excel', 'application/vnd.ms-excel [official]', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), + 'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'), 'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint'), 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'wbxml' => 'application/wbxml', -- cgit v1.2.3-24-g4f1b From c58c7821abbf4e2b6038e5e2067dc10ab5918f4a Mon Sep 17 00:00:00 2001 From: Eric Roberts Date: Wed, 15 Aug 2012 16:20:39 -0500 Subject: Remove change log entry for Bug fix #1695 Signed-off-by: Eric Roberts --- user_guide_src/source/changelog.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 3dd3caa42..827b1f090 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -321,7 +321,6 @@ Bug fixes for 3.0 - Fixed a bug (#1613) - :doc:`Form Helper ` functions ``form_multiselect()``, ``form_dropdown()`` didn't properly handle empty array option groups. - Fixed a bug (#1605) - :doc:`Pagination Library ` produced incorrect *previous* and *next* link values. - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. -- Fixed a bug (#1695) - IE8 occasionally registered as mobile browser, due to Nintedo DS user agent's "ds" key. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 64f470bfb9b4aa4e0abc984dacd543bb7d059260 Mon Sep 17 00:00:00 2001 From: Joe McFrederick Date: Sat, 18 Aug 2012 12:29:56 -0400 Subject: Fix bug #1000 --- system/core/Loader.php | 6 +++--- user_guide_src/source/changelog.rst | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/system/core/Loader.php b/system/core/Loader.php index 0bc6e844a..656934c87 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -785,11 +785,11 @@ class CI_Loader { $_ci_ext = pathinfo($_ci_view, PATHINFO_EXTENSION); $_ci_file = ($_ci_ext === '') ? $_ci_view.'.php' : $_ci_view; - foreach ($this->_ci_view_paths as $view_file => $cascade) + foreach ($this->_ci_view_paths as $_ci_view_file => $cascade) { - if (file_exists($view_file.$_ci_file)) + if (file_exists($_ci_view_file.$_ci_file)) { - $_ci_path = $view_file.$_ci_file; + $_ci_path = $_ci_view_file.$_ci_file; $file_exists = TRUE; break; } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 827b1f090..0730aafb4 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -321,6 +321,7 @@ Bug fixes for 3.0 - Fixed a bug (#1613) - :doc:`Form Helper ` functions ``form_multiselect()``, ``form_dropdown()`` didn't properly handle empty array option groups. - Fixed a bug (#1605) - :doc:`Pagination Library ` produced incorrect *previous* and *next* link values. - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. +- Fixed a bug (#1000) - Change syntax of $view_file to $_ci_view_file to prevent being overwritten by application. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 07cdcf8bb2af1c18aa93ea3c39bee8dcdf7d047e Mon Sep 17 00:00:00 2001 From: pickupman Date: Sun, 19 Aug 2012 15:33:43 -0400 Subject: Fixes issue #1678 --- system/helpers/captcha_helper.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index a4383c9d3..57ef9e2fa 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -80,8 +80,7 @@ if ( ! function_exists('create_captcha')) $current_dir = @opendir($img_path); while ($filename = @readdir($current_dir)) { - if ($filename !== '.' && $filename !== '..' && $filename !== 'index.html' - && (str_replace('.jpg', '', $filename) + $expiration) < $now) + if (strpos($filename, ".jpg") !== FALSE && (str_replace('.jpg', '', $filename) + $expiration) < $now) { @unlink($img_path.$filename); } -- cgit v1.2.3-24-g4f1b From 0b1d56f08b5d95046a367ed65c7aef6c8d717bc3 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Mon, 20 Aug 2012 17:35:38 +0200 Subject: database added config option --- application/config/database.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/config/database.php b/application/config/database.php index bb0d87be0..4c5cad03f 100644 --- a/application/config/database.php +++ b/application/config/database.php @@ -63,6 +63,7 @@ | Sites using Latin-1 or UTF-8 database character set and collation are unaffected. | ['swap_pre'] A default table prefix that should be swapped with the dbprefix | ['autoinit'] Whether or not to automatically initialize the database. +| ['compress'] Whether or not to use client compression (only MySQL and MySQLi) | ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections | - good for ensuring strict SQL while developing | ['failover'] array - A array with 0 or more data for connections if the main should fail. @@ -93,6 +94,7 @@ $db['default'] = array( 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'autoinit' => TRUE, + 'compress' => TRUE, 'stricton' => FALSE, 'failover' => array() ); -- cgit v1.2.3-24-g4f1b From c27721fbd02511c168f4c353e4f5eac1b2049e9f Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Mon, 20 Aug 2012 18:34:24 +0200 Subject: compression test --- system/database/DB_driver.php | 1 + system/database/drivers/mysqli/mysqli_driver.php | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d63a1d955..4296815f8 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,6 +51,7 @@ abstract class CI_DB_driver { public $char_set = 'utf8'; public $dbcollat = 'utf8_general_ci'; public $autoinit = TRUE; // Whether to automatically initialize the DB + public $compress = TRUE; public $swap_pre = ''; public $port = ''; public $pconnect = FALSE; diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index be61aab20..475857c84 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -65,6 +65,14 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_connect() { + if ($this->compress === TRUE) + { + $port = NULL; + + $mysqli = mysqli_init(); + return $mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); + } + return empty($this->port) ? @new mysqli($this->hostname, $this->username, $this->password, $this->database) : @new mysqli($this->hostname, $this->username, $this->password, $this->database, $this->port); -- cgit v1.2.3-24-g4f1b From 49f7b729b3633d7f29029b7800dde5cc47a022c8 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Mon, 20 Aug 2012 18:52:21 +0200 Subject: mysql driver updated --- system/database/drivers/mysql/mysql_driver.php | 18 ++++++++++++++++-- system/database/drivers/mysqli/mysqli_driver.php | 8 +++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 29db90408..35473016f 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -83,7 +83,14 @@ class CI_DB_mysql_driver extends CI_DB { */ public function db_connect() { - return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); + if ($this->compress === TRUE) + { + return @mysql_connect($this->hostname, $this->username, $this->password, TRUE, MYSQL_CLIENT_COMPRESS); + } + else + { + return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); + } } // -------------------------------------------------------------------- @@ -95,7 +102,14 @@ class CI_DB_mysql_driver extends CI_DB { */ public function db_pconnect() { - return @mysql_pconnect($this->hostname, $this->username, $this->password); + if ($this->compress === TRUE) + { + return @mysql_pconnect($this->hostname, $this->username, $this->password, MYSQL_CLIENT_COMPRESS); + } + else + { + return @mysql_pconnect($this->hostname, $this->username, $this->password); + } } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 475857c84..947c47784 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -67,10 +67,12 @@ class CI_DB_mysqli_driver extends CI_DB { { if ($this->compress === TRUE) { - $port = NULL; + $port = empty($this->port) ? NULL : $this->port; - $mysqli = mysqli_init(); - return $mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); + $link = mysqli_init(); + $link->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); + + return $link; } return empty($this->port) -- cgit v1.2.3-24-g4f1b From 0afe5d96e08b6b81768910cd0a8f63192115215a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 20 Aug 2012 11:03:14 -0700 Subject: Fixing code sample styling and footer link --- user_guide_src/source/_themes/eldocs/layout.html | 2 +- user_guide_src/source/_themes/eldocs/static/asset/css/common.css | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/_themes/eldocs/layout.html b/user_guide_src/source/_themes/eldocs/layout.html index 01db07cac..9be3b853b 100644 --- a/user_guide_src/source/_themes/eldocs/layout.html +++ b/user_guide_src/source/_themes/eldocs/layout.html @@ -125,7 +125,7 @@ {%- block footer %} {%- endblock %} diff --git a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css index 6cabda037..67d90a232 100644 --- a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css +++ b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css @@ -148,6 +148,8 @@ fieldset{ border: 0; } .top{ float: right; } +.highlight{ overflow-x: auto; } + .admonition, .highlight-ee, .highlight-ci, @@ -166,6 +168,8 @@ fieldset{ border: 0; } padding: 10px 10px 8px; } +.highlight-ci{ background-color: #FEFEFE; border-color: #E5E5E5; } + .admonition p{ margin: 0; } .codeblock{ margin: 10px 0; } -- cgit v1.2.3-24-g4f1b From 87687e10c582b085afdc649ec810a2d2cf34e98b Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 20 Aug 2012 11:05:03 -0700 Subject: fixed RST indentation error in 3.0.0 upgrade instructions code sample --- user_guide_src/source/installation/upgrade_300.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index f3a637326..64a237069 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -147,6 +147,7 @@ The :doc:`Email library <../libraries/email>` will automatically clear the set p emails. To override this behaviour, pass FALSE as the first parameter in the ``send()`` function: :: + if ($this->email->send(FALSE)) { // Parameters won't be cleared -- cgit v1.2.3-24-g4f1b From 329834e354d75ed239c83f410adacdd294ae2f64 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 20 Aug 2012 18:10:39 -0700 Subject: Switching to Sphinx's built in JavaScript search - disabled rST source copying, the contextual results for the search don't render, so they look goofy - added .highlighted class to CSS for highlighting search terms - replaced Google search form with native search form (and separated into its own theme file) - added body class to #content div for JS highlighter to hook onto --- user_guide_src/source/_themes/eldocs/layout.html | 14 +++++--------- user_guide_src/source/_themes/eldocs/searchbox.html | 21 +++++++++++++++++++++ .../_themes/eldocs/static/asset/css/common.css | 2 ++ user_guide_src/source/conf.py | 1 + 4 files changed, 29 insertions(+), 9 deletions(-) create mode 100644 user_guide_src/source/_themes/eldocs/searchbox.html diff --git a/user_guide_src/source/_themes/eldocs/layout.html b/user_guide_src/source/_themes/eldocs/layout.html index 9be3b853b..51d61b849 100644 --- a/user_guide_src/source/_themes/eldocs/layout.html +++ b/user_guide_src/source/_themes/eldocs/layout.html @@ -91,13 +91,7 @@ -
+
+ {%- block body %} {{ body }} + {%- endblock %}
{%- endblock %} @@ -129,4 +125,4 @@
{%- endblock %} - + \ No newline at end of file diff --git a/user_guide_src/source/_themes/eldocs/searchbox.html b/user_guide_src/source/_themes/eldocs/searchbox.html new file mode 100644 index 000000000..039590bd9 --- /dev/null +++ b/user_guide_src/source/_themes/eldocs/searchbox.html @@ -0,0 +1,21 @@ + + + + diff --git a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css index 67d90a232..0a63871c5 100644 --- a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css +++ b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css @@ -185,6 +185,8 @@ fieldset{ border: 0; } } .admonition-title:after{ content: ': '; } + +.highlighted{ background-color: #FFF09B; } #table-contents{ bottom: 0; diff --git a/user_guide_src/source/conf.py b/user_guide_src/source/conf.py index e972a388b..f68405b36 100644 --- a/user_guide_src/source/conf.py +++ b/user_guide_src/source/conf.py @@ -167,6 +167,7 @@ html_last_updated_fmt = '%b %d, %Y' # Output file base name for HTML help builder. htmlhelp_basename = 'CodeIgniterdoc' +html_copy_source = False # -- Options for LaTeX output -------------------------------------------------- -- cgit v1.2.3-24-g4f1b From cdb481b92de54f7069039f6d0aa92b32c4e543fa Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Tue, 21 Aug 2012 10:11:16 +0200 Subject: driver fix + userguide + changelog --- system/database/drivers/mysqli/mysqli_driver.php | 18 +++++++++++++++--- user_guide_src/source/changelog.rst | 3 ++- user_guide_src/source/database/configuration.rst | 7 ++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 947c47784..9558dfd86 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -65,14 +65,15 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_connect() { + // Use MySQL client compression? if ($this->compress === TRUE) { $port = empty($this->port) ? NULL : $this->port; - $link = mysqli_init(); - $link->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); + $mysqli = mysqli_init(); + $mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); - return $link; + return $mysqli; } return empty($this->port) @@ -95,6 +96,17 @@ class CI_DB_mysqli_driver extends CI_DB { return $this->db_connect(); } + // Use MySQL client compression? + if ($this->compress === TRUE) + { + $port = empty($this->port) ? NULL : $this->port; + + $mysqli = mysqli_init(); + $mysqli->real_connect('p:'.$this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); + + return $mysqli; + } + return empty($this->port) ? @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database) : @new mysqli('p:'.$this->hostname, $this->username, $this->password, $this->database, $this->port); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 827b1f090..bc88b3c23 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -139,8 +139,9 @@ Release Date: Not Released - Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `. - Added unbuffered_row() method for getting a row without prefetching whole result (consume less memory). - Added PDO support for ``list_fields()`` in :doc:`Database Results `. - - Added capability for packages to hold database.php config files + - Added capability for packages to hold database.php config files - Added subdrivers support (currently only used by PDO). + - Added support for client compression for MySQL and MySQLi. - Libraries diff --git a/user_guide_src/source/database/configuration.rst b/user_guide_src/source/database/configuration.rst index c17de600a..636b5b5b2 100644 --- a/user_guide_src/source/database/configuration.rst +++ b/user_guide_src/source/database/configuration.rst @@ -28,6 +28,7 @@ prototype:: 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'autoinit' => TRUE, + 'compress' => TRUE, 'stricton' => FALSE, 'failover' => array() ); @@ -69,6 +70,7 @@ These failovers can be specified by setting the failover for a connection like t 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'autoinit' => TRUE, + 'compress' => TRUE, 'stricton' => FALSE ), array( @@ -86,6 +88,7 @@ These failovers can be specified by setting the failover for a connection like t 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'autoinit' => TRUE, + 'compress' => TRUE, 'stricton' => FALSE ) ); @@ -115,6 +118,7 @@ example, to set up a "test" environment you would do this:: 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'autoinit' => TRUE, + 'compress' => TRUE, 'stricton' => FALSE, 'failover' => array() ); @@ -174,11 +178,12 @@ Explanation of Values: customizable by the end user. **autoinit** Whether or not to automatically connect to the database when the library loads. If set to false, the connection will take place prior to executing the first query. +**compress** Whether or not to use client compression for MySQL or MySQLi. **stricton** TRUE/FALSE (boolean) - Whether to force "Strict Mode" connections, good for ensuring strict SQL while developing an application. **port** The database port number. To use this value you have to add a line to the database config array. :: - + $db['default']['port'] = 5432; ====================== ================================================================================================== -- cgit v1.2.3-24-g4f1b From 9819cba2138ce1c32aa1e8a7d5938d03b4becc3e Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Tue, 21 Aug 2012 10:13:36 +0200 Subject: changelog fix --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index bc88b3c23..db074e854 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -141,7 +141,7 @@ Release Date: Not Released - Added PDO support for ``list_fields()`` in :doc:`Database Results `. - Added capability for packages to hold database.php config files - Added subdrivers support (currently only used by PDO). - - Added support for client compression for MySQL and MySQLi. + - Added client compression support for MySQL and MySQLi. - Libraries -- cgit v1.2.3-24-g4f1b From a819580fd7d921bb1687d5690712cd61eed82dd2 Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Tue, 21 Aug 2012 16:32:04 +0200 Subject: docx mimetype added --- application/config/mimes.php | 2 +- user_guide_src/source/changelog.rst | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/application/config/mimes.php b/application/config/mimes.php index 1917b11de..48771dc15 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -123,7 +123,7 @@ return array( 'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'), 'movie' => 'video/x-sgi-movie', 'doc' => array('application/msword', 'application/vnd.ms-office'), - 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'), + 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'), 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword'), 'word' => array('application/msword', 'application/octet-stream'), 'xl' => 'application/excel', diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 827b1f090..77c018a11 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -34,6 +34,7 @@ Release Date: Not Released - Added support for rar archives to mimes.php. - Updated support for xml ('application/xml') and xsl ('application/xml', 'text/xsl') files in mimes.php. - Updated support for doc files in mimes.php. + - Updated support for docx files in mimes.php. - Updated support for php files in mimes.php. - Updated support for zip files in mimes.php. - Updated support for csv files in mimes.php. @@ -139,7 +140,7 @@ Release Date: Not Released - Added PDO support for create_database(), drop_database and drop_table() in :doc:`Database Forge `. - Added unbuffered_row() method for getting a row without prefetching whole result (consume less memory). - Added PDO support for ``list_fields()`` in :doc:`Database Results `. - - Added capability for packages to hold database.php config files + - Added capability for packages to hold database.php config files - Added subdrivers support (currently only used by PDO). - Libraries -- cgit v1.2.3-24-g4f1b From 19ac8bc3fc55460660cca618b6cce0ef212e7bdc Mon Sep 17 00:00:00 2001 From: RecoilUK Date: Thu, 23 Aug 2012 20:43:48 +0200 Subject: Update user_guide_src/source/libraries/form_validation.rst --- user_guide_src/source/libraries/form_validation.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 3bcad7ba6..bc25d8292 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -488,6 +488,15 @@ the name of the function:: $this->form_validation->set_message('username_check') +If you are using an error message that can accept two $s in your error string, +such as .. + + $this->form_validation->set_message('min_length', 'The $s field must contain at least $s characters.'); + +Then you can also use %1$s and %2$s: + + $this->form_validation->set_message('min_length', 'This field must contain at least %2$s characters.'); + You can also override any error message found in the language file. For example, to change the message for the "required" rule you will do this:: -- cgit v1.2.3-24-g4f1b From aee9265602c3bb30a1f7f3dfd562b9b36cc612a4 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Sun, 26 Aug 2012 21:45:35 -0400 Subject: Fixed select_driver(), cookie sess_destroy(), and native cookie name conflict --- system/core/Loader.php | 8 +++++++- system/libraries/Session/Session.php | 11 +++++++---- system/libraries/Session/drivers/Session_cookie.php | 2 +- system/libraries/Session/drivers/Session_native.php | 3 ++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/system/core/Loader.php b/system/core/Loader.php index a62cf06f5..01d99dd37 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -911,7 +911,7 @@ class CI_Loader { $class = substr($class, $last_slash); // Check for match and driver base class - if (strtolower($subdir) == strtolower($class) && ! class_exists('CI_Driver_Library')) + if (strtolower(trim($subdir, '/')) == strtolower($class) && ! class_exists('CI_Driver_Library')) { // We aren't instantiating an object here, just making the base class available require BASEPATH.'libraries/Driver.php'; @@ -1005,6 +1005,12 @@ class CI_Loader { $path = strtolower($class).'/'.$class; return $this->_ci_load_class($path, $params); } + else if (ucfirst($subdir) != $subdir) + { + // Lowercase subdir failed - retry capitalized + $path = ucfirst($subdir).$class; + return $this->_ci_load_class($path, $params); + } // If we got this far we were unable to find the requested class. // We do not issue errors if the load call failed due to a duplicate request diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 97eab803f..1f24456a4 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -141,14 +141,17 @@ class CI_Session extends CI_Driver_Library { $child = str_replace($this->lib_name.'_', '', $driver); if (isset($this->$child)) { - // Make driver current and sync userdata - $this->current = $this->$child; - $this->userdata =& $this->current->get_userdata(); + // See if driver is already current + if ($this->$child !== $this->current) { + // Make driver current and sync userdata + $this->current = $this->$child; + $this->userdata =& $this->current->get_userdata(); + } } else { // Load new driver - $this->load_driver($driver); + $this->load_driver($child); } } } diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 8ac92e432..89e81386f 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -325,7 +325,7 @@ class CI_Session_cookie extends CI_Session_driver { public function sess_destroy() { // Kill the session DB row - if ($this->sess_use_database === TRUE && $this->has_userdata('session_id')) + if ($this->sess_use_database === TRUE && isset($this->userdata['session_id'])) { $this->CI->db->where('session_id', $this->userdata['session_id']); $this->CI->db->delete($this->sess_table_name); diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 04c985574..8ba8e749a 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -56,7 +56,8 @@ class CI_Session_native extends CI_Session_driver { // Set session name, if specified if ($config['sess_cookie_name']) { - $name = $config['sess_cookie_name']; + // Differentiate name from cookie driver with '_id' suffix + $name = $config['sess_cookie_name'].'_id'; if ($config['cookie_prefix']) { // Prepend cookie prefix -- cgit v1.2.3-24-g4f1b From 0fc3be559d23fda6ab112c01b0cd9156f201af85 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Mon, 27 Aug 2012 20:54:23 -0400 Subject: Fixed multi-driver load return and last-ditch library subdirectory retry object names --- system/core/Loader.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/core/Loader.php b/system/core/Loader.php index 01d99dd37..0d05649ca 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -633,7 +633,7 @@ class CI_Loader { { $this->driver($driver); } - return FALSE; + return; } if ($library === '') @@ -1003,13 +1003,13 @@ class CI_Loader { if ($subdir === '') { $path = strtolower($class).'/'.$class; - return $this->_ci_load_class($path, $params); + return $this->_ci_load_class($path, $params, $object_name); } else if (ucfirst($subdir) != $subdir) { // Lowercase subdir failed - retry capitalized $path = ucfirst($subdir).$class; - return $this->_ci_load_class($path, $params); + return $this->_ci_load_class($path, $params, $object_name); } // If we got this far we were unable to find the requested class. -- cgit v1.2.3-24-g4f1b From 08c8304778e573d725b5565f350e44c34fb0d830 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 28 Aug 2012 17:35:56 -0400 Subject: Minor session test improvements Signed-off-by: dchill42 --- tests/codeigniter/libraries/Session_test.php | 182 +++++++++++++++++---------- 1 file changed, 117 insertions(+), 65 deletions(-) diff --git a/tests/codeigniter/libraries/Session_test.php b/tests/codeigniter/libraries/Session_test.php index 5d58a9e69..135f71806 100644 --- a/tests/codeigniter/libraries/Session_test.php +++ b/tests/codeigniter/libraries/Session_test.php @@ -85,38 +85,66 @@ class Session_test extends CI_TestCase { /** * Test set_userdata() function + * + * @covers CI_Session::set_userdata + * @covers CI_Session::userdata */ public function test_set_userdata() { - // Set a userdata message for each driver - $cmsg = 'Some test data'; - $this->session->cookie->set_userdata('test1', $cmsg); - $nmsg = 'Other test data'; - $this->session->native->set_userdata('test1', $nmsg); + // Set userdata values for each driver + $key1 = 'test1'; + $ckey2 = 'test2'; + $nkey2 = 'test3'; + $cmsg1 = 'Some test data'; + $cmsg2 = 42; + $nmsg1 = 'Other test data'; + $nmsg2 = true; + $this->session->cookie->set_userdata($key1, $cmsg1); + $this->session->set_userdata($ckey2, $cmsg2); + $this->session->native->set_userdata($key1, $nmsg1); + $this->session->set_userdata($nkey2, $nmsg2); // Verify independent messages - $this->assertEquals($this->session->cookie->userdata('test1'), $cmsg); - $this->assertEquals($this->session->native->userdata('test1'), $nmsg); + $this->assertEquals($cmsg1, $this->session->cookie->userdata($key1)); + $this->assertEquals($nmsg1, $this->session->native->userdata($key1)); + + // Verify pre-selected driver sets + $this->assertEquals($cmsg2, $this->session->cookie->userdata($ckey2)); + $this->assertEquals($nmsg2, $this->session->native->userdata($nkey2)); + + // Verify no crossover + $this->assertNull($this->session->cookie->userdata($nkey2)); + $this->assertNull($this->session->native->userdata($ckey2)); } /** * Test the has_userdata() function + * + * @covers CI_Session::has_userdata */ public function test_has_userdata() { - // Set a userdata message for each driver + // Set a userdata value for each driver + $key = 'hastest'; $cmsg = 'My test data'; - $this->session->cookie->set_userdata('test2', $cmsg); + $this->session->cookie->set_userdata($key, $cmsg); $nmsg = 'Your test data'; - $this->session->native->set_userdata('test2', $nmsg); + $this->session->native->set_userdata($key, $nmsg); - // Verify independent messages - $this->assertTrue($this->session->cookie->has_userdata('test2')); - $this->assertTrue($this->session->native->has_userdata('test2')); + // Verify values exist + $this->assertTrue($this->session->cookie->has_userdata($key)); + $this->assertTrue($this->session->native->has_userdata($key)); + + // Verify non-existent values + $nokey = 'hasnot'; + $this->assertFalse($this->session->cookie->has_userdata($nokey)); + $this->assertFalse($this->session->native->has_userdata($nokey)); } /** * Test the all_userdata() function + * + * @covers CI_Session::all_userdata */ public function test_all_userdata() { @@ -151,90 +179,102 @@ class Session_test extends CI_TestCase { /** * Test the unset_userdata() function + * + * @covers CI_Session::unset_userdata */ public function test_unset_userdata() { // Set a userdata message for each driver + $key = 'untest'; $cmsg = 'Other test data'; - $this->session->cookie->set_userdata('test3', $cmsg); + $this->session->cookie->set_userdata($key, $cmsg); $nmsg = 'Sundry test data'; - $this->session->native->set_userdata('test3', $nmsg); + $this->session->native->set_userdata($key, $nmsg); // Verify independent messages - $this->assertEquals($this->session->cookie->userdata('test3'), $cmsg); - $this->assertEquals($this->session->native->userdata('test3'), $nmsg); + $this->assertEquals($this->session->cookie->userdata($key), $cmsg); + $this->assertEquals($this->session->native->userdata($key), $nmsg); // Unset them and verify absence - $this->session->cookie->unset_userdata('test3'); - $this->session->native->unset_userdata('test3'); - $this->assertEquals($this->session->cookie->userdata('test3'), NULL); - $this->assertEquals($this->session->native->userdata('test3'), NULL); + $this->session->cookie->unset_userdata($key); + $this->session->native->unset_userdata($key); + $this->assertNull($this->session->cookie->userdata($key)); + $this->assertNull($this->session->native->userdata($key)); } /** - * Test the set_flashdata() function + * Test the flashdata() functions + * + * @covers CI_Session::set_flashdata + * @covers CI_Session::flashdata */ - public function test_set_flashdata() + public function test_flashdata() { // Set flashdata message for each driver + $key = 'fltest'; $cmsg = 'Some flash data'; - $this->session->cookie->set_flashdata('test4', $cmsg); + $this->session->cookie->set_flashdata($key, $cmsg); $nmsg = 'Other flash data'; - $this->session->native->set_flashdata('test4', $nmsg); + $this->session->native->set_flashdata($key, $nmsg); // Simulate page reload $this->session->cookie->reload(); $this->session->native->reload(); // Verify independent messages - $this->assertEquals($this->session->cookie->flashdata('test4'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test4'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Simulate next page reload $this->session->cookie->reload(); $this->session->native->reload(); // Verify absence of messages - $this->assertEquals($this->session->cookie->flashdata('test4'), NULL); - $this->assertEquals($this->session->native->flashdata('test4'), NULL); + $this->assertNull($this->session->cookie->flashdata($key)); + $this->assertNull($this->session->native->flashdata($key)); } /** * Test the keep_flashdata() function + * + * @covers CI_Session::keep_flashdata */ public function test_keep_flashdata() { // Set flashdata message for each driver + $key = 'kfltest'; $cmsg = 'My flash data'; - $this->session->cookie->set_flashdata('test5', $cmsg); + $this->session->cookie->set_flashdata($key, $cmsg); $nmsg = 'Your flash data'; - $this->session->native->set_flashdata('test5', $nmsg); + $this->session->native->set_flashdata($key, $nmsg); // Simulate page reload and verify independent messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Keep messages - $this->session->cookie->keep_flashdata('test5'); - $this->session->native->keep_flashdata('test5'); + $this->session->cookie->keep_flashdata($key); + $this->session->native->keep_flashdata($key); // Simulate next page reload and verify message persistence $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), $cmsg); - $this->assertEquals($this->session->native->flashdata('test5'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->flashdata($key)); + $this->assertEquals($nmsg, $this->session->native->flashdata($key)); // Simulate next page reload and verify absence of messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->flashdata('test5'), NULL); - $this->assertEquals($this->session->native->flashdata('test5'), NULL); + $this->assertNull($this->session->cookie->flashdata($key)); + $this->assertNull($this->session->native->flashdata($key)); } /** * Test the all_flashdata() function + * + * @covers CI_Session::all_flashdata */ public function test_all_flashdata() { @@ -264,54 +304,63 @@ class Session_test extends CI_TestCase { } /** - * Test the set_tempdata() function + * Test the tempdata() functions + * + * @covers CI_Session::set_tempdata + * @covers CI_Session::tempdata */ public function test_set_tempdata() { // Set tempdata message for each driver - 1 second timeout + $key = 'tmptest'; $cmsg = 'Some temp data'; - $this->session->cookie->set_tempdata('test6', $cmsg, 1); + $this->session->cookie->set_tempdata($key, $cmsg, 1); $nmsg = 'Other temp data'; - $this->session->native->set_tempdata('test6', $nmsg, 1); + $this->session->native->set_tempdata($key, $nmsg, 1); // Simulate page reload and verify independent messages $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->tempdata('test6'), $cmsg); - $this->assertEquals($this->session->native->tempdata('test6'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); + $this->assertEquals($nmsg, $this->session->native->tempdata($key)); // Wait 2 seconds, simulate page reload and verify message absence sleep(2); $this->session->cookie->reload(); $this->session->native->reload(); - $this->assertEquals($this->session->cookie->tempdata('test6'), NULL); - $this->assertEquals($this->session->native->tempdata('test6'), NULL); + $this->assertNull($this->session->cookie->tempdata($key)); + $this->assertNull($this->session->native->tempdata($key)); } /** * Test the unset_tempdata() function + * + * @covers CI_Session::unset_tempdata */ public function test_unset_tempdata() { // Set tempdata message for each driver - 1 second timeout + $key = 'utmptest'; $cmsg = 'My temp data'; - $this->session->cookie->set_tempdata('test7', $cmsg, 1); + $this->session->cookie->set_tempdata($key, $cmsg, 1); $nmsg = 'Your temp data'; - $this->session->native->set_tempdata('test7', $nmsg, 1); + $this->session->native->set_tempdata($key, $nmsg, 1); // Verify independent messages - $this->assertEquals($this->session->cookie->tempdata('test7'), $cmsg); - $this->assertEquals($this->session->native->tempdata('test7'), $nmsg); + $this->assertEquals($cmsg, $this->session->cookie->tempdata($key)); + $this->assertEquals($nmsg, $this->session->native->tempdata($key)); // Unset data and verify message absence - $this->session->cookie->unset_tempdata('test7'); - $this->session->native->unset_tempdata('test7'); - $this->assertEquals($this->session->cookie->tempdata('test7'), NULL); - $this->assertEquals($this->session->native->tempdata('test7'), NULL); + $this->session->cookie->unset_tempdata($key); + $this->session->native->unset_tempdata($key); + $this->assertNull($this->session->cookie->tempdata($key)); + $this->assertNull($this->session->native->tempdata($key)); } /** * Test the sess_regenerate() function + * + * @covers CI_Session::sess_regenerate */ public function test_sess_regenerate() { @@ -320,34 +369,37 @@ class Session_test extends CI_TestCase { $oldid = $this->session->cookie->userdata('session_id'); $this->session->cookie->sess_regenerate(); $newid = $this->session->cookie->userdata('session_id'); - $this->assertFalse($oldid === $newid); + $this->assertNotEquals($oldid, $newid); // Native driver - bug #55267 (https://bugs.php.net/bug.php?id=55267) prevents testing this - /*$oldid = session_id(); - $this->session->native->sess_regenerate(); - $oldid = session_id(); - $this->assertFalse($oldid === $newid);*/ + // $oldid = session_id(); + // $this->session->native->sess_regenerate(); + // $oldid = session_id(); + // $this->assertNotEquals($oldid, $newid); } /** * Test the sess_destroy() function + * + * @covers CI_Session::sess_destroy */ public function test_sess_destroy() { // Set a userdata message, destroy session, and verify absence + $key = 'dsttest'; $msg = 'More test data'; // Cookie driver - $this->session->cookie->set_userdata('test8', $msg); - $this->assertEquals($this->session->cookie->userdata('test8'), $msg); + $this->session->cookie->set_userdata($key, $msg); + $this->assertEquals($msg, $this->session->cookie->userdata($key)); $this->session->cookie->sess_destroy(); - $this->assertEquals($this->session->cookie->userdata('test8'), NULL); + $this->assertNull($this->session->cookie->userdata($key)); // Native driver - $this->session->native->set_userdata('test8', $msg); - $this->assertEquals($this->session->native->userdata('test8'), $msg); + $this->session->native->set_userdata($key, $msg); + $this->assertEquals($msg, $this->session->native->userdata($key)); $this->session->native->sess_destroy(); - $this->assertEquals($this->session->native->userdata('test8'), NULL); + $this->assertNull($this->session->native->userdata($key)); } } -- cgit v1.2.3-24-g4f1b From 3cecd8234d3bb9045e9cc41e15f603a6e87c5fac Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 28 Aug 2012 21:37:27 -0400 Subject: Extracted cookie database saves to shutdown and cleaned up code Signed-off-by: dchill42 --- system/libraries/Session/Session.php | 35 +++ .../libraries/Session/drivers/Session_cookie.php | 269 ++++++++++----------- 2 files changed, 169 insertions(+), 135 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 1f24456a4..1195ed955 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -42,6 +42,7 @@ class CI_Session extends CI_Driver_Library { public $params = array(); protected $current = null; protected $userdata = array(); + protected $loaded = array(); const FLASHDATA_KEY = 'flash'; const FLASHDATA_NEW = ':new:'; @@ -111,6 +112,22 @@ class CI_Session extends CI_Driver_Library { log_message('debug', 'CI_Session routines successfully run'); } + /** + * CI_Session destructor + * + * The destructor calls shutdown() on each loaded driver + */ + public function __destruct() + { + // Call shutdown for each loaded driver + foreach ($this->loaded as $driver) + { + $this->$driver->shutdown(); + } + + log_message('debug', 'CI_Session Class Shutdown'); + } + /** * Loads session storage driver * @@ -122,6 +139,14 @@ class CI_Session extends CI_Driver_Library { // Save reference to most recently loaded driver as library default and sync userdata $this->current = parent::load_driver($driver); $this->userdata =& $this->current->get_userdata(); + + // Mark driver as loaded + if (!in_array($driver, $this->loaded)) + { + $this->loaded[] = $driver; + } + + // Return driver object return $this->current; } @@ -581,6 +606,16 @@ abstract class CI_Session_driver extends CI_Driver { // Overload this method to implement initialization } + /** + * Shut down driver + * + * @return void + */ + public function shutdown() + { + // Overload this method to implement shutdown + } + /** * Save the session data * diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 89e81386f..df3282cee 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -28,9 +28,7 @@ /** * Cookie-based session management driver * - * This is the CI_Session functionality, as written by EllisLab, abstracted out to a driver. - * I have done a little updating for PHP5, and made minor changes to extract this functionality from - * the public interface (now in the Session Library), but effectively this code is unchanged. + * This is the classic CI_Session functionality, as written by EllisLab, abstracted out to a driver. * * @package CodeIgniter * @subpackage Libraries @@ -172,6 +170,25 @@ class CI_Session_cookie extends CI_Session_driver { */ public $now; + /** + * Default userdata keys + * + * @var array + */ + protected $defaults = array( + 'session_id', + 'ip_address', + 'user_agent', + 'last_activity' + ); + + /** + * Data needs DB update flag + * + * @var bool + */ + protected $data_dirty = FALSE; + /** * Initialize session driver object * @@ -224,10 +241,14 @@ class CI_Session_cookie extends CI_Session_driver { $this->CI->load->library('encrypt'); } - // Are we using a database? If so, load it + // Check for database if ($this->sess_use_database === TRUE && $this->sess_table_name !== '') { + // Load database driver $this->CI->load->database(); + + // Register shutdown function + register_shutdown_function(array($this, '_update_db')); } // Set the "now" time. Can either be GMT or server time, based on the config prefs. @@ -259,6 +280,17 @@ class CI_Session_cookie extends CI_Session_driver { $this->_sess_gc(); } + /** + * Shutdown session driver object + * + * @return void + */ + public function shutdown() + { + // Just update the DB + $this->_update_db(); + } + /** * Write the session data * @@ -266,55 +298,15 @@ class CI_Session_cookie extends CI_Session_driver { */ public function sess_save() { - // Are we saving custom data to the DB? If not, all we do is update the cookie + // Check for database if ($this->sess_use_database === FALSE) { - $this->_set_cookie(); - return; - } - - // set the custom userdata, the session data we will set in a second - $custom_userdata = $this->all_userdata(); - $cookie_userdata = array(); - - // Before continuing, we need to determine if there is any custom data to deal with. - // Let's determine this by removing the default indexes to see if there's anything left in the array - // and set the session data while we're at it - $defaults = array( - 'session_id', - 'ip_address', - 'user_agent', - 'last_activity' - ); - foreach ($defaults as $val) - { - unset($custom_userdata[$val]); - $cookie_userdata[$val] = $this->userdata[$val]; + // Mark custom data as dirty so we know to update the DB + $this->data_dirty = TRUE; } - // Did we find any custom data? If not, we turn the empty array into a string - // since there's no reason to serialize and store an empty array in the DB - if (count($custom_userdata) === 0) - { - $custom_userdata = ''; - } - else - { - // Serialize the custom data array so we can store it - $custom_userdata = $this->_serialize($custom_userdata); - } - - // Run the update query - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->update($this->sess_table_name, array( - 'last_activity' => $this->userdata['last_activity'], - 'user_data' => $custom_userdata - )); - - // Write the cookie. Notice that we manually pass the cookie data array to the - // _set_cookie() function. Normally that function will store $this->userdata, but - // in this case that array contains custom data, which we do not want in the cookie. - $this->_set_cookie($cookie_userdata); + // Write the cookie + $this->_set_cookie(); } /** @@ -327,8 +319,7 @@ class CI_Session_cookie extends CI_Session_driver { // Kill the session DB row if ($this->sess_use_database === TRUE && isset($this->userdata['session_id'])) { - $this->CI->db->where('session_id', $this->userdata['session_id']); - $this->CI->db->delete($this->sess_table_name); + $this->CI->db->delete($this->sess_table_name, array('session_id' => $this->userdata['session_id'])); } // Kill the cookie @@ -392,16 +383,18 @@ class CI_Session_cookie extends CI_Session_driver { return FALSE; } - // Decrypt the cookie data + // Check for encryption if ($this->sess_encrypt_cookie === TRUE) { + // Decrypt the cookie data $session = $this->CI->encrypt->decode($session); } else { - // encryption was not used, so we need to check the md5 hash - $hash = substr($session, strlen($session)-32); // get last 32 chars - $session = substr($session, 0, strlen($session)-32); + // Encryption was not used, so we need to check the md5 hash in the last 32 chars + $len = strlen($session)-32; + $hash = substr($session, $len); + $session = substr($session, 0, $len); // Does the md5 hash match? This is to prevent manipulation of session data in userspace if ($hash !== md5($session.$this->encryption_key)) @@ -478,18 +471,13 @@ class CI_Session_cookie extends CI_Session_driver { if (is_array($custom_data)) { - foreach ($custom_data as $key => $val) - { - $session[$key] = $val; - } + $session = $session + $custom_data; } } } // Session is valid! $this->userdata = $session; - unset($session); - return TRUE; } @@ -501,28 +489,19 @@ class CI_Session_cookie extends CI_Session_driver { */ protected function _sess_create() { - $sessid = ''; - do - { - $sessid .= mt_rand(0, mt_getrandmax()); - } - while (strlen($sessid) < 32); - - // To make the session ID even more secure we'll combine it with the user's IP - $sessid .= $this->CI->input->ip_address(); - + // Initialize userdata $this->userdata = array( - 'session_id' => md5(uniqid($sessid, TRUE)), + 'session_id' => $this->_make_sess_id(), 'ip_address' => $this->CI->input->ip_address(), 'user_agent' => substr($this->CI->input->user_agent(), 0, 120), 'last_activity' => $this->now, - 'user_data' => '' ); - // Save the data to the DB if needed + // Check for database if ($this->sess_use_database === TRUE) { - $this->CI->db->query($this->CI->db->insert_string($this->sess_table_name, $this->userdata)); + // Add empty user_data field and save the data to the DB + $this->CI->db->set('user_data', '')->insert($this->sess_table_name, $this->userdata); } // Write the cookie @@ -544,42 +523,84 @@ class CI_Session_cookie extends CI_Session_driver { return; } - // _set_cookie() will handle this for us if we aren't using database sessions - // by pushing all userdata to the cookie. - $cookie_data = NULL; + // Update last activity to now + $this->userdata['last_activity'] = $this->now; + + // Save the old session id so we know which DB record to update + $old_sessid = $this->userdata['session_id']; + + // Changing the session ID during an AJAX call causes problems + if ( ! $this->CI->input->is_ajax_request()) + { + // Get new id + $this->userdata['session_id'] = $this->_make_sess_id(); + } - // Changing the session ID during an AJAX call causes problems, so we'll only update our last_activity - if ($this->CI->input->is_ajax_request()) + // Check for database + if ($this->sess_use_database === TRUE) { - $this->userdata['last_activity'] = $this->now; + // Update the session ID and last_activity field in the DB + $this->CI->db->update($this->sess_table_name, array( + 'last_activity' => $this->now, + 'session_id' => $this->userdata['session_id'] + ), array('session_id' => $old_sessid)); + } - // Update the session ID and last_activity field in the DB if needed - if ($this->sess_use_database === TRUE) - { - // set cookie explicitly to only have our session data - $cookie_data = array(); - $defaults = array( - 'session_id', - 'ip_address', - 'user_agent', - 'last_activity' - ); - foreach ($defaults as $val) - { - $cookie_data[$val] = $this->userdata[$val]; - } + // Write the cookie + $this->_set_cookie(); + } - $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, - array('last_activity' => $this->userdata['last_activity']), - array('session_id' => $this->userdata['session_id']))); + /** + * Update database with current data + * + * This gets called from the shutdown function and also + * registered with PHP to run at the end of the request + * so it's guaranteed to update even when a fatal error + * occurs. The first call makes the update and clears the + * dirty flag so it won't happen twice. + */ + public function _update_db() + { + // Check for database and dirty flag and unsaved + if ($this->sess_use_database === TRUE && $this->data_dirty === TRUE) + { + // Set up activity and data fields to be set + // If we don't find custom data, user_data will remain an empty string + $set = array( + 'last_activity' => $this->userdata['last_activity'], + 'user_data' => '' + ); + + // Get the custom userdata, leaving out the defaults + // (which get stored in the cookie) + $userdata = array_diff_key($this->userdata, $this->defaults); + + // Did we find any custom data? + if ( ! empty($userdata)) + { + // Serialize the custom data array so we can store it + $set['user_data'] = $this->_serialize($userdata); } - return $this->_set_cookie($cookie_data); + // Run the update query + // Any time we change the session id, it gets updated immediately, + // so our where clause below is always safe + $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id'])); + + // Clear dirty flag to prevent double updates + $this->data_dirty = FALSE; + + log_message('debug', 'CI_Session Data Saved To DB'); } + } - // Save the old session id so we know which record to - // update in the database if we need it - $old_sessid = $this->userdata['session_id']; + /** + * Generate a new session id + * + * @return string Hashed session id + */ + protected function _make_sess_id() + { $new_sessid = ''; do { @@ -590,32 +611,8 @@ class CI_Session_cookie extends CI_Session_driver { // To make the session ID even more secure we'll combine it with the user's IP $new_sessid .= $this->CI->input->ip_address(); - // Turn it into a hash and update the session data array - $this->userdata['session_id'] = $new_sessid = md5(uniqid($new_sessid, TRUE)); - $this->userdata['last_activity'] = $this->now; - - // Update the session ID and last_activity field in the DB if needed - if ($this->sess_use_database === TRUE) - { - // set cookie explicitly to only have our session data - $cookie_data = array(); - $defaults = array( - 'session_id', - 'ip_address', - 'user_agent', - 'last_activity' - ); - foreach ($defaults as $val) - { - $cookie_data[$val] = $this->userdata[$val]; - } - - $this->CI->db->query($this->CI->db->update_string($this->sess_table_name, - array('last_activity' => $this->now, 'session_id' => $new_sessid), array('session_id' => $old_sessid))); - } - - // Write the cookie - $this->_set_cookie($cookie_data); + // Turn it into a hash and return + return md5(uniqid($new_sessid, TRUE)); } /** @@ -641,12 +638,16 @@ class CI_Session_cookie extends CI_Session_driver { * Write the session cookie * * @access protected - * @param array Cookie name/value pairs * @return void */ - protected function _set_cookie(array $cookie_data = NULL) + protected function _set_cookie() { - if (is_null($cookie_data)) + // Get userdata (only defaults if database) + if ($this->sess_use_database === TRUE) + { + $cookie_data = array_intersect_key($this->userdata, $this->defaults); + } + else { $cookie_data = $this->userdata; } @@ -798,9 +799,7 @@ class CI_Session_cookie extends CI_Session_driver { if ((mt_rand(0, $divisor) / $divisor) < $probability) { $expire = $this->now - $this->sess_expiration; - - $this->CI->db->where('last_activity < '.$expire); - $this->CI->db->delete($this->sess_table_name); + $this->CI->db->delete($this->sess_table_name, 'last_activity < '.$expire); log_message('debug', 'Session garbage collection performed.'); } -- cgit v1.2.3-24-g4f1b From 88b636b06dd91807706e2d442d910fe8b6a3b50c Mon Sep 17 00:00:00 2001 From: dchill42 Date: Wed, 29 Aug 2012 08:47:05 -0400 Subject: Fixed defaults and database check, reverted redundant shutdown feature Signed-off-by: dchill42 --- system/libraries/Session/Session.php | 35 ---------------------- .../libraries/Session/drivers/Session_cookie.php | 21 ++++--------- 2 files changed, 5 insertions(+), 51 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 1195ed955..1f24456a4 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -42,7 +42,6 @@ class CI_Session extends CI_Driver_Library { public $params = array(); protected $current = null; protected $userdata = array(); - protected $loaded = array(); const FLASHDATA_KEY = 'flash'; const FLASHDATA_NEW = ':new:'; @@ -112,22 +111,6 @@ class CI_Session extends CI_Driver_Library { log_message('debug', 'CI_Session routines successfully run'); } - /** - * CI_Session destructor - * - * The destructor calls shutdown() on each loaded driver - */ - public function __destruct() - { - // Call shutdown for each loaded driver - foreach ($this->loaded as $driver) - { - $this->$driver->shutdown(); - } - - log_message('debug', 'CI_Session Class Shutdown'); - } - /** * Loads session storage driver * @@ -139,14 +122,6 @@ class CI_Session extends CI_Driver_Library { // Save reference to most recently loaded driver as library default and sync userdata $this->current = parent::load_driver($driver); $this->userdata =& $this->current->get_userdata(); - - // Mark driver as loaded - if (!in_array($driver, $this->loaded)) - { - $this->loaded[] = $driver; - } - - // Return driver object return $this->current; } @@ -606,16 +581,6 @@ abstract class CI_Session_driver extends CI_Driver { // Overload this method to implement initialization } - /** - * Shut down driver - * - * @return void - */ - public function shutdown() - { - // Overload this method to implement shutdown - } - /** * Save the session data * diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index df3282cee..69e5fde14 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -176,10 +176,10 @@ class CI_Session_cookie extends CI_Session_driver { * @var array */ protected $defaults = array( - 'session_id', - 'ip_address', - 'user_agent', - 'last_activity' + 'session_id' => NULL, + 'ip_address' => NULL, + 'user_agent' => NULL, + 'last_activity' => NULL ); /** @@ -280,17 +280,6 @@ class CI_Session_cookie extends CI_Session_driver { $this->_sess_gc(); } - /** - * Shutdown session driver object - * - * @return void - */ - public function shutdown() - { - // Just update the DB - $this->_update_db(); - } - /** * Write the session data * @@ -299,7 +288,7 @@ class CI_Session_cookie extends CI_Session_driver { public function sess_save() { // Check for database - if ($this->sess_use_database === FALSE) + if ($this->sess_use_database === TRUE) { // Mark custom data as dirty so we know to update the DB $this->data_dirty = TRUE; -- cgit v1.2.3-24-g4f1b From 0c886901bc013e477b8c5eb9bc5e60c91d1fac56 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 29 Aug 2012 23:23:22 +0100 Subject: Added lang mock and upload mock --- tests/mocks/core/lang.php | 15 +++++++++++++++ tests/mocks/libraries/upload.php | 3 +++ 2 files changed, 18 insertions(+) create mode 100644 tests/mocks/core/lang.php create mode 100644 tests/mocks/libraries/upload.php diff --git a/tests/mocks/core/lang.php b/tests/mocks/core/lang.php new file mode 100644 index 000000000..1b99aedb3 --- /dev/null +++ b/tests/mocks/core/lang.php @@ -0,0 +1,15 @@ + Date: Wed, 29 Aug 2012 23:23:37 +0100 Subject: Added initial upload library tests --- tests/codeigniter/libraries/Upload_test.php | 231 ++++++++++++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 tests/codeigniter/libraries/Upload_test.php diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php new file mode 100644 index 000000000..021af28a7 --- /dev/null +++ b/tests/codeigniter/libraries/Upload_test.php @@ -0,0 +1,231 @@ +upload = new Mock_Libraries_Upload(); + $obj->security = new Mock_Core_Security(); + $obj->lang = new Mock_Core_Lang(); + + $this->ci_instance($obj); + $this->upload = $obj->upload; + + vfsStreamWrapper::register(); + vfsStreamWrapper::setRoot(new vfsStreamDirectory('testDir')); + + $this->_test_dir = vfsStreamWrapper::getRoot(); + } + + function test_do_upload() + { + $this->markTestIncomplete('TODO'); + } + + function test_data() + { + $data = array( + 'file_name' => 'hello.txt', + 'file_type' => 'text/plain', + 'file_path' => '/tmp/', + 'full_path' => '/tmp/hello.txt', + 'raw_name' => 'hello', + 'orig_name' => 'hello.txt', + 'client_name' => '', + 'file_ext' => '.txt', + 'file_size' => 100, + 'is_image' => FALSE, + 'image_width' => '', + 'image_height' => '', + 'image_type' => '', + 'image_size_str' => '' + ); + + $this->upload->set_upload_path('/tmp/'); + + foreach ($data as $k => $v) + { + $this->upload->{$k} = $v; + } + + $this->assertEquals('hello.txt', $this->upload->data('file_name')); + $this->assertEquals($data, $this->upload->data()); + } + + function test_set_upload_path() + { + $this->upload->set_upload_path('/tmp/'); + $this->assertEquals('/tmp/', $this->upload->upload_path); + + $this->upload->set_upload_path('/tmp'); + $this->assertEquals('/tmp/', $this->upload->upload_path); + } + + function test_set_filename() + { + $this->markTestIncomplete('TODO'); + } + + function test_set_max_filesize() + { + $this->upload->set_max_filesize(100); + $this->assertEquals(100, $this->upload->max_size); + } + + function test_set_max_filename() + { + $this->upload->set_max_filename(100); + $this->assertEquals(100, $this->upload->max_filename); + } + + function test_set_max_width() + { + $this->upload->set_max_width(100); + $this->assertEquals(100, $this->upload->max_width); + } + + function test_set_max_height() + { + $this->upload->set_max_height(100); + $this->assertEquals(100, $this->upload->max_height); + } + + function test_set_allowed_types() + { + $this->upload->set_allowed_types('*'); + $this->assertEquals('*', $this->upload->allowed_types); + + $this->upload->set_allowed_types('foo|bar'); + $this->assertEquals(array('foo', 'bar'), $this->upload->allowed_types); + } + + function test_set_image_properties() + { + $this->markTestIncomplete('TODO'); + } + + function test_set_xss_clean() + { + $this->upload->set_xss_clean(TRUE); + $this->assertTrue($this->upload->xss_clean); + + $this->upload->set_xss_clean(FALSE); + $this->assertFalse($this->upload->xss_clean); + } + + function test_is_image() + { + $this->upload->file_type = 'image/x-png'; + $this->assertTrue($this->upload->is_image()); + + $this->upload->file_type = 'text/plain'; + $this->assertFalse($this->upload->is_image()); + } + + function test_is_allowed_filetype() + { + $this->upload->allowed_types = array('html'); + + $this->upload->file_ext = '.txt'; + $this->upload->file_type = 'text/plain'; + $this->assertFalse($this->upload->is_allowed_filetype(FALSE)); + $this->assertFalse($this->upload->is_allowed_filetype(TRUE)); + + $this->upload->file_ext = '.html'; + $this->upload->file_type = 'text/html'; + $this->assertTrue($this->upload->is_allowed_filetype(FALSE)); + $this->assertTrue($this->upload->is_allowed_filetype(TRUE)); + + $this->markTestIncomplete('Image tests'); + } + + function test_is_allowed_filesize() + { + $this->upload->max_size = 100; + $this->upload->file_size = 99; + + $this->assertTrue($this->upload->is_allowed_filesize()); + + $this->upload->file_size = 101; + $this->assertFalse($this->upload->is_allowed_filesize()); + } + + function test_is_allowed_dimensions() + { + $this->markTestIncomplete('TODO'); + } + + function test_validate_upload_path() + { + $this->upload->upload_path = ''; + $this->assertFalse($this->upload->validate_upload_path()); + + $this->upload->upload_path = vfsStream::url('testDir'); + $this->assertTrue($this->upload->validate_upload_path()); + } + + function test_get_extension() + { + $this->assertEquals('.txt', $this->upload->get_extension('hello.txt')); + $this->assertEquals('.htaccess', $this->upload->get_extension('.htaccess')); + $this->assertEquals('', $this->upload->get_extension('hello')); + } + + function test_clean_file_name() + { + $this->assertEquals('hello.txt', $this->upload->clean_file_name('hello.txt')); + $this->assertEquals('hello.txt', $this->upload->clean_file_name('%253chell>o.txt')); + } + + function test_limit_filename_length() + { + $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello.txt', 10)); + $this->assertEquals('hello.txt', $this->upload->limit_filename_length('hello-world.txt', 9)); + } + + function test_do_xss_clean() + { + $file1 = vfsStream::newFile('file1.txt')->withContent('The billy goat was waiting for them.')->at($this->_test_dir); + $file2 = vfsStream::newFile('file2.txt')->at($this->_test_dir); + $file3 = vfsStream::newFile('file3.txt')->withContent('')->at($this->_test_dir); + + $this->upload->file_temp = vfsStream::url('file1.txt'); + $this->assertTrue($this->upload->do_xss_clean()); + + $this->upload->file_temp = vfsStream::url('file2.txt'); + $this->assertFalse($this->upload->do_xss_clean()); + + $this->upload->file_temp = vfsStream::url('file3.txt'); + $this->assertFalse($this->upload->do_xss_clean()); + } + + function test_set_error() + { + $errors = array( + 'An error!' + ); + + $another = 'Another error!'; + + $this->upload->set_error($errors); + $this->assertEquals($errors, $this->upload->error_msg); + + $errors[] = $another; + $this->upload->set_error($another); + $this->assertEquals($errors, $this->upload->error_msg); + } + + function test_display_errors() + { + $this->upload->error_msg[] = 'Error test'; + $this->assertEquals('

Error test

', $this->upload->display_errors()); + } + + function test_mimes_types() + { + $this->assertEquals('text/plain', $this->upload->mimes_types('txt')); + $this->assertFalse($this->upload->mimes_types('foobar')); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 096b894c7eb0db6ab13aa4478ebf52524b429fcb Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 30 Aug 2012 00:20:36 +0100 Subject: Finished the final tests (except do_upload) --- tests/codeigniter/libraries/Upload_test.php | 53 ++++++++++++++++++++++++---- tests/mocks/uploads/ci_logo.gif | Bin 0 -> 3270 bytes 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 tests/mocks/uploads/ci_logo.gif diff --git a/tests/codeigniter/libraries/Upload_test.php b/tests/codeigniter/libraries/Upload_test.php index 021af28a7..d79a3ffc9 100644 --- a/tests/codeigniter/libraries/Upload_test.php +++ b/tests/codeigniter/libraries/Upload_test.php @@ -18,9 +18,9 @@ class Upload_test extends CI_TestCase { $this->_test_dir = vfsStreamWrapper::getRoot(); } - function test_do_upload() + function test_do_upload() { - $this->markTestIncomplete('TODO'); + $this->markTestIncomplete('We can\'t really test this at the moment because of the call to `is_uploaded_file` in do_upload which isn\'t supported by vfsStream'); } function test_data() @@ -64,7 +64,11 @@ class Upload_test extends CI_TestCase { function test_set_filename() { - $this->markTestIncomplete('TODO'); + $file1 = vfsStream::newFile('hello-world.txt')->withContent('Hello world.')->at($this->_test_dir); + $this->upload->file_ext = '.txt'; + + $this->assertEquals('helloworld.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'helloworld.txt')); + $this->assertEquals('hello-world1.txt', $this->upload->set_filename(vfsStream::url('testDir').'/', 'hello-world.txt')); } function test_set_max_filesize() @@ -102,7 +106,22 @@ class Upload_test extends CI_TestCase { function test_set_image_properties() { - $this->markTestIncomplete('TODO'); + $this->upload->file_type = 'image/gif'; + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + + $props = array( + 'image_width' => 170, + 'image_height' => 73, + 'image_type' => 'gif', + 'image_size_str' => 'width="170" height="73"' + ); + + $this->upload->set_image_properties($this->upload->file_temp); + + $this->assertEquals($props['image_width'], $this->upload->image_width); + $this->assertEquals($props['image_height'], $this->upload->image_height); + $this->assertEquals($props['image_type'], $this->upload->image_type); + $this->assertEquals($props['image_size_str'], $this->upload->image_size_str); } function test_set_xss_clean() @@ -125,7 +144,7 @@ class Upload_test extends CI_TestCase { function test_is_allowed_filetype() { - $this->upload->allowed_types = array('html'); + $this->upload->allowed_types = array('html', 'gif'); $this->upload->file_ext = '.txt'; $this->upload->file_type = 'text/plain'; @@ -137,7 +156,10 @@ class Upload_test extends CI_TestCase { $this->assertTrue($this->upload->is_allowed_filetype(FALSE)); $this->assertTrue($this->upload->is_allowed_filetype(TRUE)); - $this->markTestIncomplete('Image tests'); + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->upload->file_ext = '.gif'; + $this->upload->file_type = 'image/gif'; + $this->assertTrue($this->upload->is_allowed_filetype()); } function test_is_allowed_filesize() @@ -153,7 +175,21 @@ class Upload_test extends CI_TestCase { function test_is_allowed_dimensions() { - $this->markTestIncomplete('TODO'); + $this->upload->file_type = 'text/plain'; + $this->assertTrue($this->upload->is_allowed_dimensions()); + + $this->upload->file_type = 'image/gif'; + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + + $this->upload->max_width = 10; + $this->assertFalse($this->upload->is_allowed_dimensions()); + + $this->upload->max_width = 170; + $this->upload->max_height = 10; + $this->assertFalse($this->upload->is_allowed_dimensions()); + + $this->upload->max_height = 73; + $this->assertTrue($this->upload->is_allowed_dimensions()); } function test_validate_upload_path() @@ -198,6 +234,9 @@ class Upload_test extends CI_TestCase { $this->upload->file_temp = vfsStream::url('file3.txt'); $this->assertFalse($this->upload->do_xss_clean()); + + $this->upload->file_temp = 'tests/mocks/uploads/ci_logo.gif'; + $this->assertTrue($this->upload->do_xss_clean()); } function test_set_error() diff --git a/tests/mocks/uploads/ci_logo.gif b/tests/mocks/uploads/ci_logo.gif new file mode 100644 index 000000000..073ec14b4 Binary files /dev/null and b/tests/mocks/uploads/ci_logo.gif differ -- cgit v1.2.3-24-g4f1b From 3104e3f23724b68a396cbaf2f2b1d9677b935126 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Thu, 30 Aug 2012 00:21:19 +0100 Subject: Added PHPUnit to the development requirements of composer.json --- composer.json | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fa6dc02e4..dc098acc3 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,8 @@ { "require": { "mikey179/vfsStream": "*" - } + }, + "require-dev": { + "EHER/PHPUnit": "*" + } } \ No newline at end of file -- cgit v1.2.3-24-g4f1b From ac740abc89159fe24165105253ae6048888a16ee Mon Sep 17 00:00:00 2001 From: dchill42 Date: Thu, 30 Aug 2012 10:49:28 -0400 Subject: Added session driver config items Signed-off-by: dchill42 --- application/config/config.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/application/config/config.php b/application/config/config.php index 28fc406d1..eaccbf75e 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -265,6 +265,9 @@ $config['encryption_key'] = ''; | Session Variables |-------------------------------------------------------------------------- | +| 'sess_driver' = the driver to load: cookie (Classic), native (PHP sessions), +| or your custom driver name +| 'sess_valid_drivers' = additional valid drivers which may be loaded | 'sess_cookie_name' = the name you want for the cookie | 'sess_expiration' = the number of SECONDS you want the session to last. | by default sessions last 7200 seconds (two hours). Set to zero for no expiration. @@ -278,6 +281,8 @@ $config['encryption_key'] = ''; | 'sess_time_to_update' = how many seconds between CI refreshing Session Information | */ +$config['sess_driver'] = 'cookie'; +$config['sess_valid_drivers'] = array(); $config['sess_cookie_name'] = 'ci_session'; $config['sess_expiration'] = 7200; $config['sess_expire_on_close'] = FALSE; -- cgit v1.2.3-24-g4f1b From f8f36db2d967efe8178b78a59ead14c05f50dc12 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Thu, 30 Aug 2012 14:17:28 -0400 Subject: Added autoload drivers config, added Session and Loader changes to changelog, added Session config items to upgrade guide Signed-off-by: dchill42 --- application/config/autoload.php | 29 +++++++++++++++++----- user_guide_src/source/changelog.rst | 24 ++++++++++++++---- user_guide_src/source/installation/upgrade_300.rst | 26 +++++++++++++++---- 3 files changed, 63 insertions(+), 16 deletions(-) diff --git a/application/config/autoload.php b/application/config/autoload.php index b3e63cbf6..ff153fb48 100644 --- a/application/config/autoload.php +++ b/application/config/autoload.php @@ -46,10 +46,11 @@ | | 1. Packages | 2. Libraries -| 3. Helper files -| 4. Custom config files -| 5. Language files -| 6. Models +| 3. Drivers +| 4. Helper files +| 5. Custom config files +| 6. Language files +| 7. Models | */ @@ -75,12 +76,28 @@ $autoload['packages'] = array(); | | Prototype: | -| $autoload['libraries'] = array('database', 'session', 'xmlrpc'); +| $autoload['libraries'] = array('database', 'email', 'xmlrpc'); */ $autoload['libraries'] = array(); +/* +| ------------------------------------------------------------------- +| Auto-load Drivers +| ------------------------------------------------------------------- +| These classes are located in the system/libraries folder or in your +| application/libraries folder within their own subdirectory. They +| offer multiple interchangeable driver options. +| +| Prototype: +| +| $autoload['drivers'] = array('session', 'cache'); +*/ + +$autoload['drivers'] = array(); + + /* | ------------------------------------------------------------------- | Auto-load Helper Files @@ -139,4 +156,4 @@ $autoload['model'] = array(); /* End of file autoload.php */ -/* Location: ./application/config/autoload.php */ \ No newline at end of file +/* Location: ./application/config/autoload.php */ diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 77c018a11..d026ca3d3 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -145,9 +145,21 @@ Release Date: Not Released - Libraries - - CI_Session now respects php.ini's session.gc_probability and session.gc_divisor + - :doc:`Session Library ` changes include: + - Library changed to :doc:`Driver ` with classic Cookie driver as default. + - Added Native PHP Session driver to work with $_SESSION. + - Custom session drivers can be added anywhere in package paths and loaded with Session library. + - Session drivers interchangeable on the fly. + - New tempdata feature allows setting user data items with an expiration time. + - Added default $config['sess_driver'] and $config['sess_valid_drivers'] items to config.php file. + - Cookie driver now respects php.ini's session.gc_probability and session.gc_divisor + - Changed the Cookie driver to select only one row when using database sessions. + - Cookie driver now only writes to database at end of request when using database. + - Cookie driver now uses PHP functions for faster array manipulation when using database. + - Added all_flashdata() method to session class. Returns an associative array of only flashdata. + - Added has_userdata() method to verify existence of userdata item. + - Added tempdata(), set_tempdata(), and unset_tempdata() methods for manipulating tempdata. - Added max_filename_increment config setting for Upload library. - - CI_Loader::_ci_autoloader() is now a protected method. - :doc:`Cart library ` changes include: - It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites. - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe". @@ -171,8 +183,6 @@ Release Date: Not Released - Native PHP functions used as rules can now accept an additional parameter, other than the data itself. - Updated set_rules() to accept an array of rules as well as a string. - Fields that have empty rules set no longer run through validation (and therefore are not considered erroneous). - - Changed the :doc:`Session Library ` to select only one row when using database sessions. - - Added all_flashdata() method to session class. Returns an associative array of only flashdata. - Allowed for setting table class defaults in a config file. - Added a Wincache driver to the :doc:`Caching Library `. - Added a Redis driver to the :doc:`Caching Library `. @@ -194,7 +204,11 @@ Release Date: Not Released - Changed private methods in the :doc:`URI Library ` to protected so MY_URI can override them. - Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions). - - Added method get_vars() to the :doc:`Loader Library ` to retrieve all variables loaded with $this->load->vars(). + - :doc:`Loader Library ` changes include: + - Added method get_vars() to the Loader to retrieve all variables loaded with $this->load->vars(). + - CI_Loader::_ci_autoloader() is now a protected method. + - Added autoloading of drivers with $autoload['drivers']. + - CI_Loader::library() will now load drivers as well, for backward compatibility of converted libraries (like Session). - is_loaded() function from system/core/Commons.php now returns a reference. - $config['rewrite_short_tags'] now has no effect when using PHP 5.4 as *` to retrieve $_SERVER['REQUEST_METHOD']. diff --git a/user_guide_src/source/installation/upgrade_300.rst b/user_guide_src/source/installation/upgrade_300.rst index 64a237069..31a5c0761 100644 --- a/user_guide_src/source/installation/upgrade_300.rst +++ b/user_guide_src/source/installation/upgrade_300.rst @@ -31,8 +31,24 @@ Step 3: Remove $autoload['core'] from your config/autoload.php Use of the ``$autoload['core']`` config array has been deprecated as of CodeIgniter 1.4.1 and is now removed. Move any entries that you might have listed there to ``$autoload['libraries']`` instead. +************************************************************** +Step 4: Add new session driver items to your config/config.php +************************************************************** + +With the change from a single Session Library to the new Session Driver, two new config items have been added: + + - ``$config['sess_driver']`` selects which driver to initially load. Options are: + - 'cookie' (the default) for classic CodeIgniter cookie-based sessions + - 'native' for native PHP Session support + - the name of a custom driver you have provided (see :doc:`Session Driver <../libraries/sessions>` for more info) + - ``$config['sess_valid_drivers']`` provides an array of additional custom drivers to make available for loading + +As the new Session Driver library loads the classic Cookie driver by default and always makes 'cookie' and 'native' +available as valid drivers, neither of these configuration items are required. However, it is recommended that you +add them for clarity and ease of configuration in the future. + *************************************** -Step 4: Update your config/database.php +Step 5: Update your config/database.php *************************************** Due to 3.0.0's renaming of Active Record to Query Builder, inside your `config/database.php`, you will @@ -43,20 +59,20 @@ need to rename the `$active_record` variable to `$query_builder`. $query_builder = TRUE; ******************************* -Step 5: Move your errors folder +Step 6: Move your errors folder ******************************* In version 3.0.0, the errors folder has been moved from _application/errors* to _application/views/errors*. **************************************************************************** -Step 6: Check the calls to Array Helper's element() and elements() functions +Step 7: Check the calls to Array Helper's element() and elements() functions **************************************************************************** The default return value of these functions, when the required elements don't exist, has been changed from FALSE to NULL. *************************************************************** -Step 7: Remove usage of (previously) deprecated functionalities +Step 8: Remove usage of (previously) deprecated functionalities *************************************************************** In addition to the ``$autoload['core']`` configuration setting, there's a number of other functionalities @@ -151,4 +167,4 @@ emails. To override this behaviour, pass FALSE as the first parameter in the ``s if ($this->email->send(FALSE)) { // Parameters won't be cleared - } \ No newline at end of file + } -- cgit v1.2.3-24-g4f1b From f3fddf6e0f4b0b0976c433c139326bdcd45d2da0 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 31 Aug 2012 10:10:16 +0800 Subject: fix issue #1719 and update ip address length on captcha helper Signed-off-by: Bo-Yi Wu --- user_guide_src/source/changelog.rst | 1 + user_guide_src/source/helpers/captcha_helper.rst | 2 +- user_guide_src/source/libraries/trackback.rst | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 827b1f090..cf0d29f1b 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -51,6 +51,7 @@ Release Date: Not Released - Path constants BASEPATH, APPPATH and VIEWPATH are now (internally) defined as absolute paths. - Updated email validation methods to use ``filter_var()`` instead of PCRE. - Changed environment defaults to report all errors in 'development' and only fatal ones in 'testing' and 'production' but only display them in 'development'. + - Updated ip_address lengths from 16 to 45 for supporting ipv6 address on trackback library and captcha helper. - Helpers diff --git a/user_guide_src/source/helpers/captcha_helper.rst b/user_guide_src/source/helpers/captcha_helper.rst index 48095a11d..90244739b 100644 --- a/user_guide_src/source/helpers/captcha_helper.rst +++ b/user_guide_src/source/helpers/captcha_helper.rst @@ -102,7 +102,7 @@ Here is a table prototype CREATE TABLE captcha (   captcha_id bigint(13) unsigned NOT NULL auto_increment,   captcha_time int(10) unsigned NOT NULL,   - ip_address varchar(16) default '0' NOT NULL,   + ip_address varchar(45) NOT NULL,   word varchar(20) NOT NULL,   PRIMARY KEY `captcha_id` (`captcha_id`),   KEY `word` (`word`) diff --git a/user_guide_src/source/libraries/trackback.rst b/user_guide_src/source/libraries/trackback.rst index 07b2b2177..f9e0df882 100644 --- a/user_guide_src/source/libraries/trackback.rst +++ b/user_guide_src/source/libraries/trackback.rst @@ -114,7 +114,7 @@ store them. Here is a basic prototype for such a table:: excerpt text NOT NULL, blog_name varchar(100) NOT NULL, tb_date int(10) NOT NULL, - ip_address varchar(16) NOT NULL, + ip_address varchar(45) NOT NULL, PRIMARY KEY `tb_id` (`tb_id`), KEY `entry_id` (`entry_id`) ); -- cgit v1.2.3-24-g4f1b From cdbcbfc9dac126a87eaa34d411170ce198cb4ffe Mon Sep 17 00:00:00 2001 From: vlakoff Date: Fri, 31 Aug 2012 04:38:28 +0200 Subject: Simplification in Text Helper's character_limiter() Because the "\s" regex character class includes \r and \n, there is no need for the str_replace() part --- system/helpers/text_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 8a1f01b51..76dc04a70 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -89,7 +89,7 @@ if ( ! function_exists('character_limiter')) return $str; } - $str = preg_replace('/\s+/', ' ', str_replace(array("\r\n", "\r", "\n"), ' ', $str)); + $str = preg_replace('/\s+/', ' ', $str); if (strlen($str) <= $n) { -- cgit v1.2.3-24-g4f1b From 59d49906d631772a3532cd9fc903dc56454d7dcf Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 1 Sep 2012 05:26:08 +0200 Subject: A few forgotten double quotes in language strings Follow-up to commit 0875d69dc7b5138cc40ea2f248024b2a886a0d82 from 2012-07-15 --- system/language/english/date_lang.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/system/language/english/date_lang.php b/system/language/english/date_lang.php index 229d33d2e..6683e4c69 100644 --- a/system/language/english/date_lang.php +++ b/system/language/english/date_lang.php @@ -25,20 +25,20 @@ * @filesource */ -$lang['date_year'] = "Year"; -$lang['date_years'] = "Years"; -$lang['date_month'] = "Month"; -$lang['date_months'] = "Months"; -$lang['date_week'] = "Week"; -$lang['date_weeks'] = "Weeks"; -$lang['date_day'] = "Day"; -$lang['date_days'] = "Days"; -$lang['date_hour'] = "Hour"; -$lang['date_hours'] = "Hours"; -$lang['date_minute'] = "Minute"; -$lang['date_minutes'] = "Minutes"; -$lang['date_second'] = "Second"; -$lang['date_seconds'] = "Seconds"; +$lang['date_year'] = 'Year'; +$lang['date_years'] = 'Years'; +$lang['date_month'] = 'Month'; +$lang['date_months'] = 'Months'; +$lang['date_week'] = 'Week'; +$lang['date_weeks'] = 'Weeks'; +$lang['date_day'] = 'Day'; +$lang['date_days'] = 'Days'; +$lang['date_hour'] = 'Hour'; +$lang['date_hours'] = 'Hours'; +$lang['date_minute'] = 'Minute'; +$lang['date_minutes'] = 'Minutes'; +$lang['date_second'] = 'Second'; +$lang['date_seconds'] = 'Seconds'; $lang['UM12'] = '(UTC -12:00) Baker/Howland Island'; $lang['UM11'] = '(UTC -11:00) Niue'; -- cgit v1.2.3-24-g4f1b From 5f385d0089229acf5ba317dca0c91457d14d797f Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sun, 2 Sep 2012 23:00:25 +0200 Subject: Slightly robuster test Also, single quotes per style conventions --- system/helpers/captcha_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/helpers/captcha_helper.php b/system/helpers/captcha_helper.php index 57ef9e2fa..3aac14db8 100644 --- a/system/helpers/captcha_helper.php +++ b/system/helpers/captcha_helper.php @@ -80,7 +80,7 @@ if ( ! function_exists('create_captcha')) $current_dir = @opendir($img_path); while ($filename = @readdir($current_dir)) { - if (strpos($filename, ".jpg") !== FALSE && (str_replace('.jpg', '', $filename) + $expiration) < $now) + if (substr($filename, -4) === '.jpg' && (str_replace('.jpg', '', $filename) + $expiration) < $now) { @unlink($img_path.$filename); } -- cgit v1.2.3-24-g4f1b From 7c70d10d699d7f7ecd446bf81c9e05de0811f282 Mon Sep 17 00:00:00 2001 From: pickupman Date: Sun, 2 Sep 2012 23:40:49 -0400 Subject: Fix #1741 is_unique duplicated in documentation for Form_validation --- user_guide_src/source/libraries/form_validation.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 3bcad7ba6..39f787402 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -884,7 +884,6 @@ Rule Parameter Description 0, 1, 2, 3, etc. **is_natural_no_zero** No Returns FALSE if the form element contains anything other than a natural number, but not zero: 1, 2, 3, etc. -**is_unique** Yes Returns FALSE if the form element is not unique in a database table. is_unique[table.field] **valid_email** No Returns FALSE if the form element does not contain a valid email address. **valid_emails** No Returns FALSE if any value provided in a comma separated list is not a valid email. **valid_ip** No Returns FALSE if the supplied IP is not valid. -- cgit v1.2.3-24-g4f1b From 88dabf1c0d41d317d7bde4d3134833042b3a9f2f Mon Sep 17 00:00:00 2001 From: "D. Marshall Lemcoe Jr." Date: Mon, 3 Sep 2012 01:46:30 -0300 Subject: Update application/config/constants.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removed completely unnecessary whitespace.  --- application/config/constants.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/application/config/constants.php b/application/config/constants.php index d22d2963e..62a18e761 100644 --- a/application/config/constants.php +++ b/application/config/constants.php @@ -52,14 +52,14 @@ define('DIR_WRITE_MODE', 0777); | */ -define('FOPEN_READ', 'rb'); -define('FOPEN_READ_WRITE', 'r+b'); -define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care -define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care -define('FOPEN_WRITE_CREATE', 'ab'); -define('FOPEN_READ_WRITE_CREATE', 'a+b'); -define('FOPEN_WRITE_CREATE_STRICT', 'xb'); -define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); +define('FOPEN_READ', 'rb'); +define('FOPEN_READ_WRITE', 'r+b'); +define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care +define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care +define('FOPEN_WRITE_CREATE', 'ab'); +define('FOPEN_READ_WRITE_CREATE', 'a+b'); +define('FOPEN_WRITE_CREATE_STRICT', 'xb'); +define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b'); /* |-------------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 5e9710842dc6981f4eb03c1622eabee9b3171dea Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 3 Sep 2012 18:57:35 +0100 Subject: Added Calendar library unit test --- tests/codeigniter/libraries/Calendar_test.php | 204 ++++++++++++++++++++++++++ tests/mocks/libraries/calendar.php | 25 ++++ 2 files changed, 229 insertions(+) create mode 100644 tests/codeigniter/libraries/Calendar_test.php create mode 100644 tests/mocks/libraries/calendar.php diff --git a/tests/codeigniter/libraries/Calendar_test.php b/tests/codeigniter/libraries/Calendar_test.php new file mode 100644 index 000000000..95668d70d --- /dev/null +++ b/tests/codeigniter/libraries/Calendar_test.php @@ -0,0 +1,204 @@ +calendar = new Mock_Libraries_Calendar(); + + $this->calendar = $obj->calendar; + } + + function test_initialize() + { + $this->calendar->initialize(array( + 'month_type' => 'short', + 'start_day' => 'monday' + )); + $this->assertEquals('short', $this->calendar->month_type); + $this->assertEquals('monday', $this->calendar->start_day); + } + + /** + * @covers Mock_Libraries_Calendar::parse_template + */ + function test_generate() + { + $no_events = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
September 2011
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930 
'; + + $this->assertEquals($no_events, $this->calendar->generate(2011, 9)); + + $data = array( + 3 => 'http://example.com/news/article/2006/03/', + 7 => 'http://example.com/news/article/2006/07/', + 13 => 'http://example.com/news/article/2006/13/', + 26 => 'http://example.com/news/article/2006/26/' + ); + + $events = ' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
September 2011
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930 
'; + + $this->assertEquals($events, $this->calendar->generate(2011, 9, $data)); + } + + function test_get_month_name() + { + $this->calendar->month_type = NULL; + $this->assertEquals('January', $this->calendar->get_month_name('01')); + + $this->calendar->month_type = 'short'; + $this->assertEquals('Jan', $this->calendar->get_month_name('01')); + } + + function test_get_day_names() + { + $this->assertEquals(array( + 'Sunday', + 'Monday', + 'Tuesday', + 'Wednesday', + 'Thursday', + 'Friday', + 'Saturday' + ), $this->calendar->get_day_names('long')); + + $this->assertEquals(array( + 'Sun', + 'Mon', + 'Tue', + 'Wed', + 'Thu', + 'Fri', + 'Sat' + ), $this->calendar->get_day_names('short')); + + $this->calendar->day_type = NULL; + + $this->assertEquals(array( + 'Su', + 'Mo', + 'Tu', + 'We', + 'Th', + 'Fr', + 'Sa' + ), $this->calendar->get_day_names()); + } + + function test_adjust_date() + { + $this->assertEquals(array('month' => 8, 'year' => 2012), $this->calendar->adjust_date(8, 2012)); + $this->assertEquals(array('month' => 1, 'year' => 2013), $this->calendar->adjust_date(13, 2012)); + } + + function test_get_total_days() + { + $this->assertEquals(0, $this->calendar->get_total_days(13, 2012)); + + $this->assertEquals(31, $this->calendar->get_total_days(1, 2012)); + $this->assertEquals(28, $this->calendar->get_total_days(2, 2011)); + $this->assertEquals(29, $this->calendar->get_total_days(2, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(3, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(4, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(5, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(6, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(7, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(8, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(9, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(10, 2012)); + $this->assertEquals(30, $this->calendar->get_total_days(11, 2012)); + $this->assertEquals(31, $this->calendar->get_total_days(12, 2012)); + } + + function test_default_template() + { + $array = array( + 'table_open' => '', + 'heading_row_start' => '', + 'heading_previous_cell' => '', + 'heading_title_cell' => '', + 'heading_next_cell' => '', + 'heading_row_end' => '', + 'week_row_start' => '', + 'week_day_cell' => '', + 'week_row_end' => '', + 'cal_row_start' => '', + 'cal_cell_start' => '', + 'cal_cell_end_today' => '', + 'cal_row_end' => '', + 'table_close' => '
<<{heading}>>
{week_day}
', + 'cal_cell_start_today' => '', + 'cal_cell_content' => '{day}', + 'cal_cell_content_today' => '{day}', + 'cal_cell_no_content' => '{day}', + 'cal_cell_no_content_today' => '{day}', + 'cal_cell_blank' => ' ', + 'cal_cell_end' => '
' + ); + + $this->assertEquals($array, $this->calendar->default_template()); + } + +} \ No newline at end of file diff --git a/tests/mocks/libraries/calendar.php b/tests/mocks/libraries/calendar.php new file mode 100644 index 000000000..8fee5365e --- /dev/null +++ b/tests/mocks/libraries/calendar.php @@ -0,0 +1,25 @@ +CI = new stdClass; + $this->CI->lang = new Mock_Core_Lang(); + + if ( ! in_array('calendar_lang.php', $this->CI->lang->is_loaded, TRUE)) + { + $this->CI->lang->load('calendar'); + } + + $this->local_time = time(); + + if (count($config) > 0) + { + $this->initialize($config); + } + + log_message('debug', 'Calendar Class Initialized'); + } + +} \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 97b0d8331eecd7f3efe3a1c9a93de55a2f26e877 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 4 Sep 2012 10:09:00 -0400 Subject: Fixed issues #1756 and #1711 Signed-off-by: dchill42 --- system/libraries/Session/drivers/Session_cookie.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 69e5fde14..ce63b976f 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -309,6 +309,7 @@ class CI_Session_cookie extends CI_Session_driver { if ($this->sess_use_database === TRUE && isset($this->userdata['session_id'])) { $this->CI->db->delete($this->sess_table_name, array('session_id' => $this->userdata['session_id'])); + $this->data_dirty = FALSE; } // Kill the cookie @@ -571,11 +572,22 @@ class CI_Session_cookie extends CI_Session_driver { $set['user_data'] = $this->_serialize($userdata); } + // Is caching in effect? Turn it off + $db_cache = $this->CI->db->cache_on; + $this->CI->db->cache_off(); + // Run the update query // Any time we change the session id, it gets updated immediately, // so our where clause below is always safe $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id'])); + // Was caching in effect? + if ($db_cache) + { + // Turn it back on + $this->CI->db->cache_on(); + } + // Clear dirty flag to prevent double updates $this->data_dirty = FALSE; -- cgit v1.2.3-24-g4f1b From cd436e92ec5f9a5d0361fb186bccacb908dbea22 Mon Sep 17 00:00:00 2001 From: dchill42 Date: Tue, 4 Sep 2012 10:15:14 -0400 Subject: That doesn't go there. Put cache fix around correct query. Signed-off-by: dchill42 --- .../libraries/Session/drivers/Session_cookie.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index ce63b976f..52eeddbc4 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -444,8 +444,19 @@ class CI_Session_cookie extends CI_Session_driver { $this->CI->db->where('user_agent', $session['user_agent']); } + // Is caching in effect? Turn it off + $db_cache = $this->CI->db->cache_on; + $this->CI->db->cache_off(); + $query = $this->CI->db->limit(1)->get($this->sess_table_name); + // Was caching in effect? + if ($db_cache) + { + // Turn it back on + $this->CI->db->cache_on(); + } + // No result? Kill it! if ($query->num_rows() === 0) { @@ -572,22 +583,11 @@ class CI_Session_cookie extends CI_Session_driver { $set['user_data'] = $this->_serialize($userdata); } - // Is caching in effect? Turn it off - $db_cache = $this->CI->db->cache_on; - $this->CI->db->cache_off(); - // Run the update query // Any time we change the session id, it gets updated immediately, // so our where clause below is always safe $this->CI->db->update($this->sess_table_name, $set, array('session_id' => $this->userdata['session_id'])); - // Was caching in effect? - if ($db_cache) - { - // Turn it back on - $this->CI->db->cache_on(); - } - // Clear dirty flag to prevent double updates $this->data_dirty = FALSE; -- cgit v1.2.3-24-g4f1b From 596e48d30d91c69a3a4a0bfbd059e8fa21d88ad1 Mon Sep 17 00:00:00 2001 From: Joe McFrederick Date: Tue, 4 Sep 2012 14:25:47 -0400 Subject: Add documation to user guide for Migrations class --- user_guide_src/source/libraries/migration.rst | 134 +++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/migration.rst b/user_guide_src/source/libraries/migration.rst index 5192f1f29..cb7d96a6d 100644 --- a/user_guide_src/source/libraries/migration.rst +++ b/user_guide_src/source/libraries/migration.rst @@ -2,4 +2,136 @@ Migrations Class ################ -Coming soon. \ No newline at end of file +Migrations are a convenient way for you to alter your database in a +structured and organized manner. You could edit fragments of SQL by hand +but you would then be responsible for telling other developers that they +need to go and run them. You would also have to keep track of which changes +need to be run against the production machines next time you deploy. + +The database table **migration** tracks which migrations have already been +run so all you have to do is update your application files and +call **$this->migrate->current()** to work out which migrations should be run. +The current version is found in **config/migration.php**. + +****************** +Create a Migration +****************** + +.. note:: Each Migration is run in numerical order forward or backwards + depending on the method taken. Use a prefix of 3 numbers followed by an + underscore for the filename of your migration. + +This will be the first migration for a new site which has a blog. All +migrations go in the folder **application/migrations/** and have names such +as: **001_add_blog.php**.:: + + defined('BASEPATH') OR exit('No direct script access allowed'); + + class Migration_Add_blog extends CI_Migration { + + public function up() + { + $this->dbforge->add_field(array( + 'blog_id' => array( + 'type' => 'INT', + 'constraint' => 5, + 'unsigned' => TRUE, + 'auto_increment' => TRUE + ), + 'blog_title' => array( + 'type' => 'VARCHAR', + 'constraint' => '100', + ), + 'blog_description' => array( + 'type' => 'TEXT', + 'null' => TRUE, + ), + )); + + $this->dbforge->create_table('blog'); + } + + public function down() + { + $this->dbforge->drop_table('blog'); + } + +Then in **application/config/migration.php** set **$config['migration_version'] = 1;**. + +************* +Usage Example +************* + +In this example some simple code is placed in **application/controllers/migrate.php** +to update the schema.:: + + $this->load->library('migration'); + + if ( ! $this->migration->current()) + { + show_error($this->migration->error_string()); + } + +****************** +Function Reference +****************** + +There are five available methods for the Migration class: + +- $this->migration->current(); +- $this->migration->error_string(); +- $this->migration->find_migrations(); +- $this->migration->latest(); +- $this->migration->version(); + +$this->migration->current() +============================ + +The current migration is whatever is set for **$config['migration_version']** in +**application/config/migration.php**. + +$this->migration->error_string() +================================= + +This returns a string of errors while performing a migration. + +$this->migration->find_migrations() +==================================== + +An array of migration filenames are returned that are found in the **migration_path** +property. + +$this->migration->latest() +=========================== + +This works much the same way as current() but instead of looking for +the **$config['migration_version']** the Migration class will use the very +newest migration found in the filesystem. + +$this->migration->version() +============================ + +Version can be used to roll back changes or step forwards programmatically to +specific versions. It works just like current but ignores **$config['migration_version']**.:: + + $this->load->library('migration'); + + $this->migration->version(5); + +********************* +Migration Preferences +********************* + +The following is a table of all the config options for migrations. + +========================== ====================== ============= ============================================= +Preference Default Options Description +========================== ====================== ============= ============================================= +**migration_enabled** FALSE TRUE / FALSE Enable or disable migrations. +**migration_path** APPPATH.'migrations/' None The path to your migrations folder. +**migration_version** 0 None The current version your database should use. +**migration_table** migrations None The table name for storing the shema + version number. +**migration_auto_latest** FALSE TRUE / FALSE Enable or disable automatically + running migrations. +========================== ====================== ============= ============================================= -- cgit v1.2.3-24-g4f1b From 62a5ee3e430bd18a8ca8afa0d704967e8bd25763 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 4 Sep 2012 23:12:49 +0200 Subject: More complicated but faster method Also added a comment to explain the reason for such a complicated method --- system/helpers/text_helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index 76dc04a70..b592f3cc0 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -89,7 +89,8 @@ if ( ! function_exists('character_limiter')) return $str; } - $str = preg_replace('/\s+/', ' ', $str); + // a bit complicated, but faster than preg_replace with \s+ + $str = preg_replace('/ {2,}/', ' ', str_replace(array("\r", "\n", "\t", "\x0B", "\x0C"), ' ', $str)); if (strlen($str) <= $n) { -- cgit v1.2.3-24-g4f1b From 9ffcee60140b20ca3ec4e7688f83a039c7c080f7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Sep 2012 16:25:16 +0300 Subject: Cleanup and optimize new Session classes --- system/libraries/Session/Session.php | 155 ++++++++++++++------- .../libraries/Session/drivers/Session_cookie.php | 125 +++++++++-------- .../libraries/Session/drivers/Session_native.php | 69 +++++---- 3 files changed, 221 insertions(+), 128 deletions(-) diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index 1f24456a4..e6f6050c0 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -2,20 +2,31 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer + * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2006 - 2012 EllisLab, Inc. + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com * @since Version 2.0 * @filesource */ - /** - * CI_Session Class + * CodeIgniter Session Class * * The user interface defined by EllisLabs, now with puggable drivers to manage different storage mechanisms. * By default, the cookie session driver will load, but the 'sess_driver' config/param item (see above) can be @@ -35,12 +46,13 @@ * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team * @link http://codeigniter.com/user_guide/libraries/sessions.html */ class CI_Session extends CI_Driver_Library { + public $params = array(); - protected $current = null; + protected $current = NULL; protected $userdata = array(); const FLASHDATA_KEY = 'flash'; @@ -69,10 +81,10 @@ class CI_Session extends CI_Driver_Library { 'Session_cookie' ); $key = 'sess_valid_drivers'; - $drivers = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); + $drivers = isset($params[$key]) ? $params[$key] : $CI->config->item($key); if ($drivers) { - if ( ! is_array($drivers)) $drivers = array($drivers); + is_array($drivers) OR $drivers = array($drivers); // Add driver names to valid list foreach ($drivers as $driver) @@ -86,8 +98,12 @@ class CI_Session extends CI_Driver_Library { // Get driver to load $key = 'sess_driver'; - $driver = (isset($params[$key])) ? $params[$key] : $CI->config->item($key); - if ( ! $driver) $driver = 'cookie'; + $driver = isset($params[$key]) ? $params[$key] : $CI->config->item($key); + if ( ! $driver) + { + $driver = 'cookie'; + } + if ( ! in_array('session_'.strtolower($driver), array_map('strtolower', $this->valid_drivers))) { $this->valid_drivers[] = 'Session_'.$driver; @@ -111,6 +127,8 @@ class CI_Session extends CI_Driver_Library { log_message('debug', 'CI_Session routines successfully run'); } + // ------------------------------------------------------------------------ + /** * Loads session storage driver * @@ -125,6 +143,8 @@ class CI_Session extends CI_Driver_Library { return $this->current; } + // ------------------------------------------------------------------------ + /** * Select default session storage driver * @@ -142,7 +162,8 @@ class CI_Session extends CI_Driver_Library { if (isset($this->$child)) { // See if driver is already current - if ($this->$child !== $this->current) { + if ($this->$child !== $this->current) + { // Make driver current and sync userdata $this->current = $this->$child; $this->userdata =& $this->current->get_userdata(); @@ -156,6 +177,8 @@ class CI_Session extends CI_Driver_Library { } } + // ------------------------------------------------------------------------ + /** * Destroy the current session * @@ -167,19 +190,23 @@ class CI_Session extends CI_Driver_Library { $this->current->sess_destroy(); } + // ------------------------------------------------------------------------ + /** * Regenerate the current session * - * @param boolean Destroy session data flag (default: false) + * @param bool Destroy session data flag (default: false) * @return void */ - public function sess_regenerate($destroy = false) + public function sess_regenerate($destroy = FALSE) { // Call regenerate on driver and resync userdata $this->current->sess_regenerate($destroy); $this->userdata =& $this->current->get_userdata(); } + // ------------------------------------------------------------------------ + /** * Fetch a specific item from the session array * @@ -188,10 +215,11 @@ class CI_Session extends CI_Driver_Library { */ public function userdata($item) { - // Return value or NULL if not found - return ( ! isset($this->userdata[$item])) ? NULL : $this->userdata[$item]; + return isset($this->userdata[$item]) ? $this->userdata[$item] : NULL; } + // ------------------------------------------------------------------------ + /** * Fetch all session data * @@ -199,10 +227,11 @@ class CI_Session extends CI_Driver_Library { */ public function all_userdata() { - // Return entire array - return ( ! isset($this->userdata)) ? NULL : $this->userdata; + return isset($this->userdata) ? $this->userdata : NULL; } + // ------------------------------------------------------------------------ + /** * Fetch all flashdata * @@ -225,6 +254,8 @@ class CI_Session extends CI_Driver_Library { return $out; } + // ------------------------------------------------------------------------ + /** * Add or change data in the "userdata" array * @@ -253,6 +284,8 @@ class CI_Session extends CI_Driver_Library { $this->current->sess_save(); } + // ------------------------------------------------------------------------ + /** * Delete a session variable from the "userdata" array * @@ -270,7 +303,7 @@ class CI_Session extends CI_Driver_Library { // Unset each item name if (count($newdata) > 0) { - foreach ($newdata as $key => $val) + foreach (array_keys($newdata) as $key) { unset($this->userdata[$key]); } @@ -280,18 +313,21 @@ class CI_Session extends CI_Driver_Library { $this->current->sess_save(); } + // ------------------------------------------------------------------------ + /** * Determine if an item exists * * @param string Item name - * @return boolean + * @return bool */ public function has_userdata($item) { - // Check for item name return isset($this->userdata[$item]); } + // ------------------------------------------------------------------------ + /** * Add or change flashdata, only available until the next request * @@ -318,6 +354,8 @@ class CI_Session extends CI_Driver_Library { } } + // ------------------------------------------------------------------------ + /** * Keeps existing flashdata available to next request. * @@ -335,6 +373,8 @@ class CI_Session extends CI_Driver_Library { $this->set_userdata($new_flashdata_key, $value); } + // ------------------------------------------------------------------------ + /** * Fetch a specific flashdata item from the session array * @@ -348,13 +388,14 @@ class CI_Session extends CI_Driver_Library { return $this->userdata($flashdata_key); } + // ------------------------------------------------------------------------ + /** - * Add or change tempdata, only available - * until expiration + * Add or change tempdata, only available until expiration * * @param mixed Item name or array of items * @param string Item value or empty string - * @param int Item lifetime in seconds or 0 for default + * @param int Item lifetime in seconds or 0 for default * @return void */ public function set_tempdata($newdata = array(), $newval = '', $expire = 0) @@ -390,6 +431,8 @@ class CI_Session extends CI_Driver_Library { $this->set_userdata(self::EXPIRATION_KEY, $expirations); } + // ------------------------------------------------------------------------ + /** * Delete a temporary session variable from the "userdata" array * @@ -400,7 +443,7 @@ class CI_Session extends CI_Driver_Library { { // Get expirations list $expirations = $this->userdata(self::EXPIRATION_KEY); - if ( ! $expirations || ! count($expirations)) + if (empty($expirations)) { // Nothing to do return; @@ -415,7 +458,7 @@ class CI_Session extends CI_Driver_Library { // Prepend each item name and unset if (count($newdata) > 0) { - foreach ($newdata as $key => $val) + foreach (array_keys($newdata) as $key) { $tempdata_key = self::FLASHDATA_KEY.self::FLASHDATA_EXP.$key; unset($expirations[$tempdata_key]); @@ -427,6 +470,8 @@ class CI_Session extends CI_Driver_Library { $this->set_userdata(self::EXPIRATION_KEY, $expirations); } + // ------------------------------------------------------------------------ + /** * Fetch a specific tempdata item from the session array * @@ -440,17 +485,17 @@ class CI_Session extends CI_Driver_Library { return $this->userdata($tempdata_key); } + // ------------------------------------------------------------------------ + /** * Identifies flashdata as 'old' for removal * when _flashdata_sweep() runs. * - * @access protected * @return void */ protected function _flashdata_mark() { - $userdata = $this->all_userdata(); - foreach ($userdata as $name => $value) + foreach ($this->all_userdata() as $name => $value) { $parts = explode(self::FLASHDATA_NEW, $name); if (is_array($parts) && count($parts) === 2) @@ -462,16 +507,17 @@ class CI_Session extends CI_Driver_Library { } } + // ------------------------------------------------------------------------ + /** * Removes all flashdata marked as 'old' * - * @access protected * @return void */ protected function _flashdata_sweep() { $userdata = $this->all_userdata(); - foreach ($userdata as $key => $value) + foreach (array_keys($userdata) as $key) { if (strpos($key, self::FLASHDATA_OLD)) { @@ -480,17 +526,18 @@ class CI_Session extends CI_Driver_Library { } } + // ------------------------------------------------------------------------ + /** * Removes all expired tempdata * - * @access protected * @return void */ protected function _tempdata_sweep() { // Get expirations list $expirations = $this->userdata(self::EXPIRATION_KEY); - if ( ! $expirations || ! count($expirations)) + if (empty($expirations)) { // Nothing to do return; @@ -499,7 +546,7 @@ class CI_Session extends CI_Driver_Library { // Unset expired elements $now = time(); $userdata = $this->all_userdata(); - foreach ($userdata as $key => $value) + foreach (array_keys($userdata) as $key) { if (strpos($key, self::FLASHDATA_EXP) && $expirations[$key] < $now) { @@ -511,9 +558,10 @@ class CI_Session extends CI_Driver_Library { // Update expiration list $this->set_userdata(self::EXPIRATION_KEY, $expirations); } + } -// END CI_Session Class +// ------------------------------------------------------------------------ /** * CI_Session_driver Class @@ -535,9 +583,10 @@ class CI_Session extends CI_Driver_Library { * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team */ abstract class CI_Session_driver extends CI_Driver { + /** * Decorate * @@ -555,6 +604,8 @@ abstract class CI_Session_driver extends CI_Driver { $this->initialize(); } + // ------------------------------------------------------------------------ + /** * __call magic method * @@ -571,6 +622,8 @@ abstract class CI_Session_driver extends CI_Driver { return parent::__call($method, $args); } + // ------------------------------------------------------------------------ + /** * Initialize driver * @@ -581,50 +634,56 @@ abstract class CI_Session_driver extends CI_Driver { // Overload this method to implement initialization } + // ------------------------------------------------------------------------ + /** * Save the session data * - * Data in the array has changed - perform any storage synchronization necessary - * The child class MUST implement this abstract method! + * Data in the array has changed - perform any storage synchronization + * necessary. The child class MUST implement this abstract method! * * @return void */ abstract public function sess_save(); + // ------------------------------------------------------------------------ + /** * Destroy the current session * - * Clean up storage for this session - it has been terminated + * Clean up storage for this session - it has been terminated. * The child class MUST implement this abstract method! * * @return void */ abstract public function sess_destroy(); + // ------------------------------------------------------------------------ + /** * Regenerate the current session * - * Regenerate the session id + * Regenerate the session ID. * The child class MUST implement this abstract method! * - * @param boolean Destroy session data flag (default: false) + * @param bool Destroy session data flag (default: false) * @return void */ - abstract public function sess_regenerate($destroy = false); + abstract public function sess_regenerate($destroy = FALSE); + + // ------------------------------------------------------------------------ /** * Get a reference to user data array * - * Give array access to the main CI_Session object + * Give array access to the main CI_Session object. * The child class MUST implement this abstract method! * * @return array Reference to userdata */ abstract public function &get_userdata(); -} -// END CI_Session_driver Class +} /* End of file Session.php */ -/* Location: ./system/libraries/Session/Session.php */ -?> +/* Location: ./system/libraries/Session/Session.php */ \ No newline at end of file diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 52eeddbc4..6d931c16c 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -37,6 +37,7 @@ * @link http://codeigniter.com/user_guide/libraries/sessions.html */ class CI_Session_cookie extends CI_Session_driver { + /** * Whether to encrypt the session cookie * @@ -192,7 +193,6 @@ class CI_Session_cookie extends CI_Session_driver { /** * Initialize session driver object * - * @access protected * @return void */ protected function initialize() @@ -220,16 +220,17 @@ class CI_Session_cookie extends CI_Session_driver { 'cookie_prefix', 'encryption_key' ); + foreach ($prefs as $key) { - $this->$key = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : - $this->CI->config->item($key); + $this->$key = isset($this->_parent->params[$key]) + ? $this->_parent->params[$key] + : $this->CI->config->item($key); } if ($this->encryption_key === '') { - show_error('In order to use the Cookie Session driver you are required to set an encryption key '. - 'in your config file.'); + show_error('In order to use the Cookie Session driver you are required to set an encryption key in your config file.'); } // Load the string helper so we can use the strip_slashes() function @@ -280,6 +281,8 @@ class CI_Session_cookie extends CI_Session_driver { $this->_sess_gc(); } + // ------------------------------------------------------------------------ + /** * Write the session data * @@ -298,6 +301,8 @@ class CI_Session_cookie extends CI_Session_driver { $this->_set_cookie(); } + // ------------------------------------------------------------------------ + /** * Destroy the current session * @@ -320,15 +325,17 @@ class CI_Session_cookie extends CI_Session_driver { $this->userdata = array(); } + // ------------------------------------------------------------------------ + /** * Regenerate the current session * * Regenerate the session id * - * @param boolean Destroy session data flag (default: false) + * @param bool Destroy session data flag (default: false) * @return void */ - public function sess_regenerate($destroy = false) + public function sess_regenerate($destroy = FALSE) { // Check destroy flag if ($destroy) @@ -344,21 +351,23 @@ class CI_Session_cookie extends CI_Session_driver { } } + // ------------------------------------------------------------------------ + /** * Get a reference to user data array * - * @return array - Reference to userdata + * @return array Reference to userdata */ public function &get_userdata() { - // Return reference to array return $this->userdata; } + // ------------------------------------------------------------------------ + /** * Fetch the current session data if it exists * - * @access protected * @return bool */ protected function _sess_read() @@ -389,8 +398,7 @@ class CI_Session_cookie extends CI_Session_driver { // Does the md5 hash match? This is to prevent manipulation of session data in userspace if ($hash !== md5($session.$this->encryption_key)) { - log_message('error', 'The session cookie data did not match what was expected. '. - 'This could be a possible hacking attempt.'); + log_message('error', 'The session cookie data did not match what was expected. This could be a possible hacking attempt.'); $this->sess_destroy(); return FALSE; } @@ -400,8 +408,7 @@ class CI_Session_cookie extends CI_Session_driver { $session = $this->_unserialize($session); // Is the session data we unserialized an array with the correct format? - if ( ! is_array($session) || ! isset($session['session_id'], $session['ip_address'], $session['user_agent'], - $session['last_activity'])) + if ( ! is_array($session) OR ! isset($session['session_id'], $session['ip_address'], $session['user_agent'], $session['last_activity'])) { $this->sess_destroy(); return FALSE; @@ -423,7 +430,7 @@ class CI_Session_cookie extends CI_Session_driver { // Does the User Agent Match? if ($this->sess_match_useragent === TRUE && - trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120))) + trim($session['user_agent']) !== trim(substr($this->CI->input->user_agent(), 0, 120))) { $this->sess_destroy(); return FALSE; @@ -482,10 +489,11 @@ class CI_Session_cookie extends CI_Session_driver { return TRUE; } + // ------------------------------------------------------------------------ + /** * Create a new session * - * @access protected * @return void */ protected function _sess_create() @@ -509,11 +517,12 @@ class CI_Session_cookie extends CI_Session_driver { $this->_set_cookie(); } + // ------------------------------------------------------------------------ + /** * Update an existing session * - * @access protected - * @param boolean Force update flag (default: false) + * @param bool Force update flag (default: false) * @return void */ protected function _sess_update($force = FALSE) @@ -551,6 +560,8 @@ class CI_Session_cookie extends CI_Session_driver { $this->_set_cookie(); } + // ------------------------------------------------------------------------ + /** * Update database with current data * @@ -559,6 +570,8 @@ class CI_Session_cookie extends CI_Session_driver { * so it's guaranteed to update even when a fatal error * occurs. The first call makes the update and clears the * dirty flag so it won't happen twice. + * + * @return void */ public function _update_db() { @@ -595,6 +608,8 @@ class CI_Session_cookie extends CI_Session_driver { } } + // ------------------------------------------------------------------------ + /** * Generate a new session id * @@ -616,15 +631,16 @@ class CI_Session_cookie extends CI_Session_driver { return md5(uniqid($new_sessid, TRUE)); } + // ------------------------------------------------------------------------ + /** * Get the "now" time * - * @access protected * @return int Time */ protected function _get_time() { - if ($this->time_reference === 'local' || $this->time_reference === date_default_timezone_get()) + if ($this->time_reference === 'local' OR $this->time_reference === date_default_timezone_get()) { return time(); } @@ -635,36 +651,27 @@ class CI_Session_cookie extends CI_Session_driver { return mktime($hour, $minute, $second, $month, $day, $year); } + // ------------------------------------------------------------------------ + /** * Write the session cookie * - * @access protected * @return void */ protected function _set_cookie() { // Get userdata (only defaults if database) - if ($this->sess_use_database === TRUE) - { - $cookie_data = array_intersect_key($this->userdata, $this->defaults); - } - else - { - $cookie_data = $this->userdata; - } + $cookie_data = ($this->sess_use_database === TRUE) + ? array_intersect_key($this->userdata, $this->defaults) + : $this->userdata; // Serialize the userdata for the cookie $cookie_data = $this->_serialize($cookie_data); - if ($this->sess_encrypt_cookie === TRUE) - { - $cookie_data = $this->CI->encrypt->encode($cookie_data); - } - else - { + $cookie_data = ($this->sess_encrypt_cookie === TRUE) + ? $this->CI->encrypt->encode($cookie_data) // if encryption is not used, we provide an md5 hash to prevent userside tampering - $cookie_data = $cookie_data.md5($cookie_data.$this->encryption_key); - } + : $cookie_data.md5($cookie_data.$this->encryption_key); $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); @@ -673,35 +680,35 @@ class CI_Session_cookie extends CI_Session_driver { $this->cookie_secure, $this->cookie_httponly); } + // ------------------------------------------------------------------------ + /** * Set a cookie with the system * * This abstraction of the setcookie call allows overriding for unit testing * - * @access protected - * @param string Cookie name - * @param string Cookie value - * @param int Expiration time - * @param string Cookie path - * @param string Cookie domain - * @param bool Secure connection flag - * @param bool HTTP protocol only flag - * @return void - */ - protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = false, - $httponly = false) + * @param string Cookie name + * @param string Cookie value + * @param int Expiration time + * @param string Cookie path + * @param string Cookie domain + * @param bool Secure connection flag + * @param bool HTTP protocol only flag + * @return void + */ + protected function _setcookie($name, $value = '', $expire = 0, $path = '', $domain = '', $secure = FALSE, $httponly = FALSE) { - // Set the cookie setcookie($name, $value, $expire, $path, $domain, $secure, $httponly); } + // ------------------------------------------------------------------------ + /** * Serialize an array * * This function first converts any slashes found in the array to a temporary * marker, so when it gets unserialized the slashes will be preserved * - * @access protected * @param mixed Data to serialize * @return string Serialized data */ @@ -715,15 +722,17 @@ class CI_Session_cookie extends CI_Session_driver { { $data = str_replace('\\', '{{slash}}', $data); } + return serialize($data); } + // ------------------------------------------------------------------------ + /** * Escape slashes * * This function converts any slashes found into a temporary marker * - * @access protected * @param string Value * @param string Key * @return void @@ -736,13 +745,14 @@ class CI_Session_cookie extends CI_Session_driver { } } + // ------------------------------------------------------------------------ + /** * Unserialize * * This function unserializes a data string, then converts any * temporary slash markers back to actual slashes * - * @access protected * @param mixed Data to unserialize * @return mixed Unserialized data */ @@ -759,12 +769,13 @@ class CI_Session_cookie extends CI_Session_driver { return is_string($data) ? str_replace('{{slash}}', '\\', $data) : $data; } + // ------------------------------------------------------------------------ + /** * Unescape slashes * * This function converts any slash markers back into actual slashes * - * @access protected * @param string Value * @param string Key * @return void @@ -777,13 +788,14 @@ class CI_Session_cookie extends CI_Session_driver { } } + // ------------------------------------------------------------------------ + /** * Garbage collection * * This deletes expired session rows from database * if the probability percentage is met * - * @access protected * @return void */ protected function _sess_gc() @@ -805,7 +817,8 @@ class CI_Session_cookie extends CI_Session_driver { log_message('debug', 'Session garbage collection performed.'); } } + } /* End of file Session_cookie.php */ -/* Location: ./system/libraries/Session/drivers/Session_cookie.php */ +/* Location: ./system/libraries/Session/drivers/Session_cookie.php */ \ No newline at end of file diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 8ba8e749a..c97e15356 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -2,18 +2,29 @@ /** * CodeIgniter * - * An open source application development framework for PHP 5.1.6 or newer + * An open source application development framework for PHP 5.2.4 or newer + * + * NOTICE OF LICENSE + * + * Licensed under the Open Software License version 3.0 + * + * This source file is subject to the Open Software License (OSL 3.0) that is + * bundled with this package in the files license.txt / license.rst. It is + * also available through the world wide web at this URL: + * http://opensource.org/licenses/OSL-3.0 + * If you did not receive a copy of the license and are unable to obtain it + * through the world wide web, please send an email to + * licensing@ellislab.com so we can send you a copy immediately. * * @package CodeIgniter - * @author ExpressionEngine Dev Team - * @copyright Copyright (c) 2008 - 2010, EllisLab, Inc. - * @license http://codeigniter.com/user_guide/license.html + * @author EllisLab Dev Team + * @copyright Copyright (c) 2008 - 2012, EllisLab, Inc. (http://ellislab.com/) + * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) * @link http://codeigniter.com - * @since Version 2.0 + * @since Version 1.0 * @filesource */ - /** * Native PHP session management driver * @@ -22,13 +33,13 @@ * @package CodeIgniter * @subpackage Libraries * @category Sessions - * @author ExpressionEngine Dev Team + * @author EllisLab Dev Team */ class CI_Session_native extends CI_Session_driver { + /** * Initialize session driver object * - * @access protected * @return void */ protected function initialize() @@ -47,10 +58,12 @@ class CI_Session_native extends CI_Session_driver { 'cookie_path', 'cookie_domain' ); + foreach ($prefs as $key) { - $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] : - $CI->config->item($key); + $config[$key] = isset($this->_parent->params[$key]) + ? $this->_parent->params[$key] + : $CI->config->item($key); } // Set session name, if specified @@ -75,11 +88,13 @@ class CI_Session_native extends CI_Session_driver { // Default to 2 years if expiration is "0" $expire = ($config['sess_expiration'] == 0) ? (60*60*24*365*2) : $config['sess_expiration']; } + if ($config['cookie_path']) { // Use specified path $path = $config['cookie_path']; } + if ($config['cookie_domain']) { // Use specified domain @@ -98,14 +113,14 @@ class CI_Session_native extends CI_Session_driver { // Expired - destroy $destroy = TRUE; } - else if ($config['sess_match_ip'] == TRUE && isset($_SESSION['ip_address']) && - $_SESSION['ip_address'] != $CI->input->ip_address()) + elseif ($config['sess_match_ip'] === TRUE && isset($_SESSION['ip_address']) + && $_SESSION['ip_address'] !== $CI->input->ip_address()) { // IP doesn't match - destroy $destroy = TRUE; } - else if ($config['sess_match_useragent'] == TRUE && isset($_SESSION['user_agent']) && - $_SESSION['user_agent'] != trim(substr($CI->input->user_agent(), 0, 50))) + elseif ($config['sess_match_useragent'] === TRUE && isset($_SESSION['user_agent']) + && $_SESSION['user_agent'] !== trim(substr($CI->input->user_agent(), 0, 50))) { // Agent doesn't match - destroy $destroy = TRUE; @@ -120,8 +135,8 @@ class CI_Session_native extends CI_Session_driver { } // Check for update time - if ($config['sess_time_to_update'] && isset($_SESSION['last_activity']) && - ($_SESSION['last_activity'] + $config['sess_time_to_update']) < $now) + if ($config['sess_time_to_update'] && isset($_SESSION['last_activity']) + && ($_SESSION['last_activity'] + $config['sess_time_to_update']) < $now) { // Regenerate ID, but don't destroy session $this->sess_regenerate(FALSE); @@ -131,12 +146,13 @@ class CI_Session_native extends CI_Session_driver { $_SESSION['last_activity'] = $now; // Set matching values as required - if ($config['sess_match_ip'] == TRUE && !isset($_SESSION['ip_address'])) + if ($config['sess_match_ip'] === TRUE && ! isset($_SESSION['ip_address'])) { // Store user IP address $_SESSION['ip_address'] = $CI->input->ip_address(); } - if ($config['sess_match_useragent'] == TRUE && !isset($_SESSION['user_agent'])) + + if ($config['sess_match_useragent'] === TRUE && ! isset($_SESSION['user_agent'])) { // Store user agent string $_SESSION['user_agent'] = trim(substr($CI->input->user_agent(), 0, 50)); @@ -146,10 +162,11 @@ class CI_Session_native extends CI_Session_driver { $_SESSION['session_id'] = session_id(); } + // ------------------------------------------------------------------------ + /** * Save the session data * - * @access public * @return void */ public function sess_save() @@ -157,10 +174,11 @@ class CI_Session_native extends CI_Session_driver { // Nothing to do - changes to $_SESSION are automatically saved } + // ------------------------------------------------------------------------ + /** * Destroy the current session * - * @access public * @return void */ public function sess_destroy() @@ -178,13 +196,14 @@ class CI_Session_native extends CI_Session_driver { session_destroy(); } + // ------------------------------------------------------------------------ + /** * Regenerate the current session * * Regenerate the session id * - * @access public - * @param boolean Destroy session data flag (default: FALSE) + * @param bool Destroy session data flag (default: FALSE) * @return void */ public function sess_regenerate($destroy = FALSE) @@ -194,10 +213,11 @@ class CI_Session_native extends CI_Session_driver { $_SESSION['session_id'] = session_id(); } + // ------------------------------------------------------------------------ + /** * Get a reference to user data array * - * @access public * @return array Reference to userdata */ public function &get_userdata() @@ -205,7 +225,8 @@ class CI_Session_native extends CI_Session_driver { // Just return reference to $_SESSION return $_SESSION; } + } /* End of file Session_native.php */ -/* Location: ./system/libraries/Session/drivers/Session_native.php */ +/* Location: ./system/libraries/Session/drivers/Session_native.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3f3f135ed5b47fd87a59d31fb3d1a4c773dcc3b3 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 5 Sep 2012 16:39:28 +0300 Subject: Misc. style changes --- system/libraries/Session/drivers/Session_cookie.php | 2 +- system/libraries/Xmlrpc.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 6d931c16c..4f415cc0d 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -347,7 +347,7 @@ class CI_Session_cookie extends CI_Session_driver { else { // Just force an update to recreate the id - $this->_sess_update(true); + $this->_sess_update(TRUE); } } diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php index cbb91c40a..a8aaa2088 100644 --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1359,7 +1359,7 @@ class XML_RPC_Values extends CI_Xmlrpc if ($type === $this->xmlrpcBoolean) { - $val = (int) (strcasecmp($val,'true') === 0 OR $val === 1 OR ($val === TRUE && strcasecmp($val, 'false'))); + $val = (int) (strcasecmp($val, 'true') === 0 OR $val === 1 OR ($val === TRUE && strcasecmp($val, 'false'))); } if ($this->mytype === 2) -- cgit v1.2.3-24-g4f1b From 44558109c8fc0ae7a223e6fae6b44f6598b2d3ad Mon Sep 17 00:00:00 2001 From: Jonathan Bonnefoy Date: Wed, 5 Sep 2012 15:41:42 +0200 Subject: Database display error supporting "Loader.php" and "MY_Loader.php" --- system/database/DB_driver.php | 2 +- user_guide_src/source/changelog.rst | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 4296815f8..76f9433d2 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1353,7 +1353,7 @@ abstract class CI_DB_driver { $trace = debug_backtrace(); foreach ($trace as $call) { - if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE) + if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE && preg_match('#core/(MY_)?Loader#', $call['file']) === 0 ) { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 578e60ec0..ce45f8f03 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -143,6 +143,7 @@ Release Date: Not Released - Added capability for packages to hold database.php config files - Added subdrivers support (currently only used by PDO). - Added client compression support for MySQL and MySQLi. + - Removed Loader class from Database error to better find the likely culprit. - Libraries -- cgit v1.2.3-24-g4f1b From 747a326c22c335a4c55df77762164b2b9626f919 Mon Sep 17 00:00:00 2001 From: Jonathan Bonnefoy Date: Wed, 5 Sep 2012 18:17:21 +0200 Subject: Check for "Loader" in $call['class'] instead of $call['file'] --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 76f9433d2..9628e9a9e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1353,7 +1353,7 @@ abstract class CI_DB_driver { $trace = debug_backtrace(); foreach ($trace as $call) { - if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE && preg_match('#core/(MY_)?Loader#', $call['file']) === 0 ) + if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE && isset($call['class']) && strpos($call['class'], 'Loader') !== FALSE) { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']); -- cgit v1.2.3-24-g4f1b From f7e23b3357c73cc9eb50c59f444181fcfaa2267d Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Fri, 7 Sep 2012 09:52:32 +0100 Subject: Removed the   from the default config variables in the pagination class. Fixes #187 and #208 Signed-off-by: Alex Bilbie --- system/libraries/Pagination.php | 16 ++++++++-------- user_guide_src/source/changelog.rst | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 5573f6407..4fa605ca9 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -52,20 +52,20 @@ class CI_Pagination { protected $full_tag_open = ''; protected $full_tag_close = ''; protected $first_tag_open = ''; - protected $first_tag_close = ' '; - protected $last_tag_open = ' '; + protected $first_tag_close = ''; + protected $last_tag_open = ''; protected $last_tag_close = ''; protected $first_url = ''; // Alternative URL for the First Page. - protected $cur_tag_open = ' '; + protected $cur_tag_open = ''; protected $cur_tag_close = ''; - protected $next_tag_open = ' '; - protected $next_tag_close = ' '; - protected $prev_tag_open = ' '; + protected $next_tag_open = ''; + protected $next_tag_close = ''; + protected $prev_tag_open = ''; protected $prev_tag_close = ''; - protected $num_tag_open = ' '; + protected $num_tag_open = ''; protected $num_tag_close = ''; protected $page_query_string = FALSE; - protected $query_string_segment = 'per_page'; + protected $query_string_segment = 'per_page'; protected $display_pages = TRUE; protected $_attributes = ''; protected $_link_types = array(); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 0835a9c01..f7dfc84ac 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -201,6 +201,7 @@ Release Date: Not Released - Added support for setting custom attributes. - Deprecated usage of the "anchor_class" setting (use the new "attributes" setting instead). - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments. + - Removed the default `` `` from a number of the configuration variables. - Added the ability to use a proxy with the :doc:`XML-RPC Library `. - Core -- cgit v1.2.3-24-g4f1b From aab26a12a98ca99d956ef24e36c2262938631d73 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Tue, 11 Sep 2012 13:10:21 +0200 Subject: Better server test in redirect() of URL helper "Location" header bugs are specific to IIS; previous test was matching all HTTP servers under Windows. This test isn't perfect yet ($_SERVER['SERVER_SOFTWARE'], which corresponds to the "Server" header of HTTP response, might be missing), but there is no perfect test. "Refresh" method makes the window blank for quite a noticeable time, so let's not affect other servers because of IIS. --- system/helpers/url_helper.php | 2 +- user_guide_src/source/helpers/url_helper.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 57208c948..b1f5eccf1 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -534,7 +534,7 @@ if ( ! function_exists('redirect')) } // IIS environment likely? Use 'refresh' for better compatibility - if (DIRECTORY_SEPARATOR !== '/' && $method === 'auto') + if ($method === 'auto' && isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== FALSE) { $method = 'refresh'; } diff --git a/user_guide_src/source/helpers/url_helper.rst b/user_guide_src/source/helpers/url_helper.rst index 305454048..8de7817e4 100644 --- a/user_guide_src/source/helpers/url_helper.rst +++ b/user_guide_src/source/helpers/url_helper.rst @@ -303,7 +303,7 @@ link. The function will build the URL based on your config file values. The optional second parameter allows you to force a particular redirection method. The available methods are "location" or "refresh", with location -being faster but less reliable on Windows servers. The default is "auto", +being faster but less reliable on IIS servers. The default is "auto", which will attempt to intelligently choose the method based on the server environment. -- cgit v1.2.3-24-g4f1b From e3162843d9c2ca7e35f09741b6a361813473d4c5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 12 Sep 2012 14:44:26 +0300 Subject: Minor adjustments --- system/database/DB_driver.php | 2 +- user_guide_src/source/changelog.rst | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 9628e9a9e..e61af91b7 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1353,7 +1353,7 @@ abstract class CI_DB_driver { $trace = debug_backtrace(); foreach ($trace as $call) { - if (isset($call['file']) && strpos($call['file'], BASEPATH.'database') === FALSE && isset($call['class']) && strpos($call['class'], 'Loader') !== FALSE) + if (isset($call['file'], $call['class']) && strpos($call['file'], BASEPATH.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE) { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index f7dfc84ac..481afeee3 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -51,8 +51,8 @@ Release Date: Not Released - Changed detection of ``$view_folder`` so that if it's not found in the current path, it will now also be searched for under the application folder. - Path constants BASEPATH, APPPATH and VIEWPATH are now (internally) defined as absolute paths. - Updated email validation methods to use ``filter_var()`` instead of PCRE. - - Changed environment defaults to report all errors in 'development' and only fatal ones in 'testing' and 'production' but only display them in 'development'. - - Updated ip_address lengths from 16 to 45 for supporting ipv6 address on trackback library and captcha helper. + - Changed environment defaults to report all errors in *development* and only fatal ones in *testing*, *production* but only display them in *development*. + - Updated *ip_address* database field lengths from 16 to 45 for supporting IPv6 address on :doc:`Trackback Library ` and :doc:`Captcha Helper `. - Helpers @@ -144,7 +144,7 @@ Release Date: Not Released - Added capability for packages to hold database.php config files - Added subdrivers support (currently only used by PDO). - Added client compression support for MySQL and MySQLi. - - Removed Loader class from Database error to better find the likely culprit. + - Removed :doc:`Loader Class ` from Database error to better find the likely culprit. - Libraries @@ -201,7 +201,7 @@ Release Date: Not Released - Added support for setting custom attributes. - Deprecated usage of the "anchor_class" setting (use the new "attributes" setting instead). - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments. - - Removed the default `` `` from a number of the configuration variables. + - Removed the default `` `` from a number of the configuration variables. - Added the ability to use a proxy with the :doc:`XML-RPC Library `. - Core @@ -340,7 +340,7 @@ Bug fixes for 3.0 - Fixed a bug (#1613) - :doc:`Form Helper ` functions ``form_multiselect()``, ``form_dropdown()`` didn't properly handle empty array option groups. - Fixed a bug (#1605) - :doc:`Pagination Library ` produced incorrect *previous* and *next* link values. - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. -- Fixed a bug (#1000) - Change syntax of $view_file to $_ci_view_file to prevent being overwritten by application. +- Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 88e3857ec2328e1dc4168c8343367d9d9e54d019 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 12 Sep 2012 18:45:21 +0200 Subject: Updated .travis.yml with new services param MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See http://about.travis-ci.org/blog/august-2012-upcoming-ci-environment-updates/ for details --- .travis.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.travis.yml b/.travis.yml index 2496def0b..62acf05e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,11 @@ language: php php: - 5.3 - 5.4 + +services: + - mysql + - postgresql + - sqlite env: - DB=mysql -- cgit v1.2.3-24-g4f1b From 8280885499ca4b1cffacc9ad78a9eff07a84de25 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Thu, 13 Sep 2012 05:19:59 +0200 Subject: directory_map() was skipping files and directories named "0" Close #1757. Thanks @BennyC! --- system/helpers/directory_helper.php | 2 +- tests/codeigniter/helpers/directory_helper_test.php | 4 +++- user_guide_src/source/changelog.rst | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/system/helpers/directory_helper.php b/system/helpers/directory_helper.php index e7d3b5e8a..7d6b6770e 100644 --- a/system/helpers/directory_helper.php +++ b/system/helpers/directory_helper.php @@ -62,7 +62,7 @@ if ( ! function_exists('directory_map')) while (FALSE !== ($file = readdir($fp))) { // Remove '.', '..', and hidden files [optional] - if ( ! trim($file, '.') OR ($hidden === FALSE && $file[0] === '.')) + if ($file === '.' OR $file === '..' OR ($hidden === FALSE && $file[0] === '.')) { continue; } diff --git a/tests/codeigniter/helpers/directory_helper_test.php b/tests/codeigniter/helpers/directory_helper_test.php index 176ff1d78..c39ccd8d0 100644 --- a/tests/codeigniter/helpers/directory_helper_test.php +++ b/tests/codeigniter/helpers/directory_helper_test.php @@ -19,6 +19,7 @@ class Directory_helper_test extends CI_TestCase { 'benchmark.html' => '', 'database' => array('active_record.html' => '', 'binds.html' => ''), 'email.html' => '', + '0' => '', '.hiddenfile.txt' => '' ) ); @@ -30,7 +31,8 @@ class Directory_helper_test extends CI_TestCase { 'libraries' => array( 'benchmark.html', 'database' => array('active_record.html', 'binds.html'), - 'email.html' + 'email.html', + '0' ) ); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 481afeee3..66dd0ea05 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -341,6 +341,7 @@ Bug fixes for 3.0 - Fixed a bug (#1605) - :doc:`Pagination Library ` produced incorrect *previous* and *next* link values. - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. - Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application. +- Fixed a bug (#1757) - :doc:`Directory Helper ` function ``directory_map()`` was skipping files and directories named *0*. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 431afaedaea55bc20716babe21557fd2b0ad531c Mon Sep 17 00:00:00 2001 From: Taufan Aditya Date: Fri, 14 Sep 2012 00:57:41 +0700 Subject: Set code-coverage limit scope Signed-off-by: Taufan Aditya --- tests/travis/mysql.phpunit.xml | 2 +- tests/travis/pdo/mysql.phpunit.xml | 2 +- tests/travis/pdo/pgsql.phpunit.xml | 2 +- tests/travis/pdo/sqlite.phpunit.xml | 2 +- tests/travis/pgsql.phpunit.xml | 2 +- tests/travis/sqlite.phpunit.xml | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/travis/mysql.phpunit.xml b/tests/travis/mysql.phpunit.xml index 38c8eba48..06d4a011b 100644 --- a/tests/travis/mysql.phpunit.xml +++ b/tests/travis/mysql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../system diff --git a/tests/travis/pdo/mysql.phpunit.xml b/tests/travis/pdo/mysql.phpunit.xml index c3113a66f..7121edc45 100644 --- a/tests/travis/pdo/mysql.phpunit.xml +++ b/tests/travis/pdo/mysql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../../system diff --git a/tests/travis/pdo/pgsql.phpunit.xml b/tests/travis/pdo/pgsql.phpunit.xml index 232025523..df3ff986e 100644 --- a/tests/travis/pdo/pgsql.phpunit.xml +++ b/tests/travis/pdo/pgsql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../../system diff --git a/tests/travis/pdo/sqlite.phpunit.xml b/tests/travis/pdo/sqlite.phpunit.xml index 3d1256721..7d867f6d1 100644 --- a/tests/travis/pdo/sqlite.phpunit.xml +++ b/tests/travis/pdo/sqlite.phpunit.xml @@ -18,7 +18,7 @@ - + ../../../system diff --git a/tests/travis/pgsql.phpunit.xml b/tests/travis/pgsql.phpunit.xml index 51e433d76..bfddbf6b5 100644 --- a/tests/travis/pgsql.phpunit.xml +++ b/tests/travis/pgsql.phpunit.xml @@ -18,7 +18,7 @@ - + ../../system diff --git a/tests/travis/sqlite.phpunit.xml b/tests/travis/sqlite.phpunit.xml index 701165734..75c946aee 100644 --- a/tests/travis/sqlite.phpunit.xml +++ b/tests/travis/sqlite.phpunit.xml @@ -18,7 +18,7 @@ - + ../../system -- cgit v1.2.3-24-g4f1b From 5f733c4fd1369a185804cd7b6d27debc50ab1826 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sat, 15 Sep 2012 10:48:17 +0200 Subject: Update reserved names documentation - EXT removed in 079fbfcde095230f304e889217f897031a948f61 - VIEWPATH added in 8eef9c77512d4fad5357d3cbda83b89f844d7d16 --- user_guide_src/source/general/reserved_names.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/general/reserved_names.rst b/user_guide_src/source/general/reserved_names.rst index 5ce7fc2ff..3354375c5 100644 --- a/user_guide_src/source/general/reserved_names.rst +++ b/user_guide_src/source/general/reserved_names.rst @@ -45,11 +45,11 @@ Constants --------- - ENVIRONMENT -- EXT - FCPATH - SELF - BASEPATH - APPPATH +- VIEWPATH - CI_VERSION - FILE_READ_MODE - FILE_WRITE_MODE -- cgit v1.2.3-24-g4f1b From b16dd29147fa8155cb9d9dadfb7c587aef81d772 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sun, 16 Sep 2012 19:11:39 +0200 Subject: Minor change in Output cache file check Won't change anything in practice, but robuster (and faster) if ever a cache file would be invalid --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/core/Output.php b/system/core/Output.php index 9842f834d..847c61e3e 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -552,7 +552,7 @@ class CI_Output { fclose($fp); // Strip out the embedded timestamp - if ( ! preg_match('/\d+TS--->/', $cache, $match)) + if ( ! preg_match('/^\d+TS--->/', $cache, $match)) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 239e0e598f0b9462e195db5da658095eb70cf6e3 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Sun, 16 Sep 2012 19:16:33 +0200 Subject: Better method for getting Output cache file embedded timestamp Faster, shorter code --- system/core/Output.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/core/Output.php b/system/core/Output.php index 847c61e3e..052367ed6 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -552,13 +552,13 @@ class CI_Output { fclose($fp); // Strip out the embedded timestamp - if ( ! preg_match('/^\d+TS--->/', $cache, $match)) + if ( ! preg_match('/^(\d+)TS--->/', $cache, $match)) { return FALSE; } $last_modified = filemtime($cache_path); - $expire = str_replace('TS--->', '', $match[0]); + $expire = $match[1]; // Has the file expired? if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path)) -- cgit v1.2.3-24-g4f1b From 530b946191c68886b6e156004742e785bfeef8cc Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 17 Sep 2012 14:18:07 +0200 Subject: redirect() documentation: add a note for IIS users --- user_guide_src/source/helpers/url_helper.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/user_guide_src/source/helpers/url_helper.rst b/user_guide_src/source/helpers/url_helper.rst index 8de7817e4..1987dfb72 100644 --- a/user_guide_src/source/helpers/url_helper.rst +++ b/user_guide_src/source/helpers/url_helper.rst @@ -325,3 +325,7 @@ engine purposes. The default Response Code is 302. The third parameter is .. note:: For very fine grained control over headers, you should use the `Output Library ` set_header() function. + +.. note:: To IIS users: if you hide the `Server` HTTP header, the "auto" + method won't detect IIS, in that case it is advised you explicitly + use the "refresh" method. -- cgit v1.2.3-24-g4f1b From 035f499a59f9a226fa1223387074ef4e28abd4bb Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 17 Sep 2012 14:45:21 +0200 Subject: Changelog: add entry for the change in "auto" method of redirect() --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index f7dfc84ac..ed1b33835 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -67,6 +67,7 @@ Release Date: Not Released - ``anchor_popup()`` will now fill the "href" attribute with the URL and its JS code will return false instead. - Added JS window name support to ``anchor_popup()`` function. - Added support (auto-detection) for HTTP/1.1 response code 303 in ``redirect()``. + - "auto" method in ``redirect()`` now chooses the "refresh" method only on IIS servers, instead of all servers on Windows. - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper `. - Changed ``humanize()`` to include a second param for the separator. - Refactored ``plural()`` and ``singular()`` to avoid double pluralization and support more words. -- cgit v1.2.3-24-g4f1b From 935d42f91a55a409ca02857ef1ef660c921ff1db Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 19 Sep 2012 16:17:03 +0100 Subject: Ignore composer vendor directory Signed-off-by: Alex Bilbie --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 11fb6d67c..a035c2b27 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ application/logs/* user_guide_src/build/* user_guide_src/cilexer/build/* user_guide_src/cilexer/dist/* -user_guide_src/cilexer/pycilexer.egg-info/* \ No newline at end of file +user_guide_src/cilexer/pycilexer.egg-info/* +/vendor/ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 8d6e0c568657064a23a60d286124b81ff3e37dcc Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 19 Sep 2012 16:20:53 +0100 Subject: Added a contributing file to appear in pull requests and issues https://github.com/blog/1184-contributing-guidelines Signed-off-by: Alex Bilbie --- contributing | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ readme.rst | 160 ----------------------------------------------------------- 2 files changed, 159 insertions(+), 160 deletions(-) create mode 100644 contributing diff --git a/contributing b/contributing new file mode 100644 index 000000000..0519b38cb --- /dev/null +++ b/contributing @@ -0,0 +1,159 @@ +########################### +Contributing to CodeIgniter +########################### + +CodeIgniter is a community driven project and accepts contributions of code +and documentation from the community. These contributions are made in the form +of Issues or `Pull Requests `_ on +the `EllisLab CodeIgniter repository +`_ on GitHub. + +Issues are a quick way to point out a bug. If you find a bug or documentation +error in CodeIgniter then please check a few things first: + +- There is not already an open Issue +- The issue has already been fixed (check the develop branch, or look for + closed Issues) +- Is it something really obvious that you fix it yourself? + +Reporting issues is helpful but an even better approach is to send a Pull +Request, which is done by "Forking" the main repository and committing to your +own copy. This will require you to use the version control system called Git. + +********** +Guidelines +********** + +Before we look into how, here are the guidelines. If your Pull Requests fail +to pass these guidelines it will be declined and you will need to re-submit +when you’ve made the changes. This might sound a bit tough, but it is required +for us to maintain quality of the code-base. + +PHP Style +========= + +All code must meet the `Style Guide +`_, which is +essentially the `Allman indent style +`_, underscores and +readable operators. This makes certain that all code is the same format as the +existing code and means it will be as readable as possible. + +Documentation +============= + +If you change anything that requires a change to documentation then you will +need to add it. New classes, methods, parameters, changing default values, etc +are all things that will require a change to documentation. The change-log +must also be updated for every change. Also PHPDoc blocks must be maintained. + +Compatibility +============= + +CodeIgniter is compatible with PHP 5.2.4 so all code supplied must stick to +this requirement. If PHP 5.3 or 5.4 functions or features are used then there +must be a fallback for PHP 5.2.4. + +Branching +========= + +CodeIgniter uses the `Git-Flow +`_ branching model +which requires all pull requests to be sent to the "develop" branch. This is +where the next planned version will be developed. The "master" branch will +always contain the latest stable version and is kept clean so a "hotfix" (e.g: +an emergency security patch) can be applied to master to create a new version, +without worrying about other features holding it up. For this reason all +commits need to be made to "develop" and any sent to "master" will be closed +automatically. If you have multiple changes to submit, please place all +changes into their own branch on your fork. + +One thing at a time: A pull request should only contain one change. That does +not mean only one commit, but one change - however many commits it took. The +reason for this is that if you change X and Y but send a pull request for both +at the same time, we might really want X but disagree with Y, meaning we +cannot merge the request. Using the Git-Flow branching model you can create +new branches for both of these features and send two requests. + +Signing +======= +You must sign your work, certifying that you either wrote the work or +otherwise have the right to pass it on to an open source project. git makes +this trivial as you merely have to use `--signoff` on your commits to your +CodeIgniter fork. + +:: + + git commit --signoff + +or simply:: + + git commit -s + +This will sign your commits with the information setup in your git config, e.g. + + Signed-off-by: John Q Public + +If you are using Tower there is a "Sign-Off" checkbox in the commit window. You +could even alias git commit to use the -s flag so you don’t have to think about +it. + +By signing your work in this manner, you certify to a "Developer's Certificate +or Origin". The current version of this certificate is in the `DCO.txt` file +in the root of this repository. + + +************ +How-to Guide +************ + +There are two ways to make changes, the easy way and the hard way. Either way +you will need to `create a GitHub account `_. + +Easy way GitHub allows in-line editing of files for making simple typo changes +and quick-fixes. This is not the best way as you are unable to test the code +works. If you do this you could be introducing syntax errors, etc, but for a +Git-phobic user this is good for a quick-fix. + +Hard way The best way to contribute is to "clone" your fork of CodeIgniter to +your development area. That sounds like some jargon, but "forking" on GitHub +means "making a copy of that repo to your account" and "cloning" means +"copying that code to your environment so you can work on it". + +#. Set up Git (Windows, Mac & Linux) +#. Go to the CodeIgniter repo +#. Fork it +#. Clone your CodeIgniter repo: git@github.com:/CodeIgniter.git +#. Checkout the "develop" branch At this point you are ready to start making + changes. +#. Fix existing bugs on the Issue tracker after taking a look to see nobody + else is working on them. +#. Commit the files +#. Push your develop branch to your fork +#. Send a pull request http://help.github.com/send-pull-requests/ + +The Reactor Engineers will now be alerted about the change and at least one of +the team will respond. If your change fails to meet the guidelines it will be +bounced, or feedback will be provided to help you improve it. + +Once the Reactor Engineer handling your pull request is happy with it they +will post it to the internal EllisLab discussion area to be double checked by +the other Engineers and EllisLab developers. If nobody has a problem with the +change then it will be merged into develop and will be part of the next +release. Keeping your fork up-to-date + +Unlike systems like Subversion, Git can have multiple remotes. A remote is the +name for a URL of a Git repository. By default your fork will have a remote +named "origin" which points to your fork, but you can add another remote named +"codeigniter" which points to git://github.com/EllisLab/CodeIgniter.git. This +is a read-only remote but you can pull from this develop branch to update your +own. + +If you are using command-line you can do the following: + +#. git remote add codeigniter git://github.com/EllisLab/CodeIgniter.git +#. git pull codeigniter develop +#. git push origin develop + +Now your fork is up to date. This should be done regularly, or before you send +a pull request at least. \ No newline at end of file diff --git a/readme.rst b/readme.rst index b211ad7cd..8628645c6 100644 --- a/readme.rst +++ b/readme.rst @@ -38,166 +38,6 @@ Installation Please see the `installation section `_ of the CodeIgniter User Guide. -************ -Contributing -************ - -CodeIgniter is a community driven project and accepts contributions of code -and documentation from the community. These contributions are made in the form -of Issues or `Pull Requests `_ on -the `EllisLab CodeIgniter repository -`_ on GitHub. - -Issues are a quick way to point out a bug. If you find a bug or documentation -error in CodeIgniter then please check a few things first: - -- There is not already an open Issue -- The issue has already been fixed (check the develop branch, or look for - closed Issues) -- Is it something really obvious that you fix it yourself? - -Reporting issues is helpful but an even better approach is to send a Pull -Request, which is done by "Forking" the main repository and committing to your -own copy. This will require you to use the version control system called Git. - -********** -Guidelines -********** - -Before we look into how, here are the guidelines. If your Pull Requests fail -to pass these guidelines it will be declined and you will need to re-submit -when you’ve made the changes. This might sound a bit tough, but it is required -for us to maintain quality of the code-base. - -PHP Style -========= - -All code must meet the `Style Guide -`_, which is -essentially the `Allman indent style -`_, underscores and -readable operators. This makes certain that all code is the same format as the -existing code and means it will be as readable as possible. - -Documentation -============= - -If you change anything that requires a change to documentation then you will -need to add it. New classes, methods, parameters, changing default values, etc -are all things that will require a change to documentation. The change-log -must also be updated for every change. Also PHPDoc blocks must be maintained. - -Compatibility -============= - -CodeIgniter is compatible with PHP 5.2.4 so all code supplied must stick to -this requirement. If PHP 5.3 or 5.4 functions or features are used then there -must be a fallback for PHP 5.2.4. - -Branching -========= - -CodeIgniter uses the `Git-Flow -`_ branching model -which requires all pull requests to be sent to the "develop" branch. This is -where the next planned version will be developed. The "master" branch will -always contain the latest stable version and is kept clean so a "hotfix" (e.g: -an emergency security patch) can be applied to master to create a new version, -without worrying about other features holding it up. For this reason all -commits need to be made to "develop" and any sent to "master" will be closed -automatically. If you have multiple changes to submit, please place all -changes into their own branch on your fork. - -One thing at a time: A pull request should only contain one change. That does -not mean only one commit, but one change - however many commits it took. The -reason for this is that if you change X and Y but send a pull request for both -at the same time, we might really want X but disagree with Y, meaning we -cannot merge the request. Using the Git-Flow branching model you can create -new branches for both of these features and send two requests. - -Signing -======= -You must sign your work, certifying that you either wrote the work or -otherwise have the right to pass it on to an open source project. git makes -this trivial as you merely have to use `--signoff` on your commits to your -CodeIgniter fork. - -:: - - git commit --signoff - -or simply:: - - git commit -s - -This will sign your commits with the information setup in your git config, e.g. - - Signed-off-by: John Q Public - -If you are using Tower there is a "Sign-Off" checkbox in the commit window. You -could even alias git commit to use the -s flag so you don’t have to think about -it. - -By signing your work in this manner, you certify to a "Developer's Certificate -or Origin". The current version of this certificate is in the `DCO.txt` file -in the root of this repository. - - -************ -How-to Guide -************ - -There are two ways to make changes, the easy way and the hard way. Either way -you will need to `create a GitHub account `_. - -Easy way GitHub allows in-line editing of files for making simple typo changes -and quick-fixes. This is not the best way as you are unable to test the code -works. If you do this you could be introducing syntax errors, etc, but for a -Git-phobic user this is good for a quick-fix. - -Hard way The best way to contribute is to "clone" your fork of CodeIgniter to -your development area. That sounds like some jargon, but "forking" on GitHub -means "making a copy of that repo to your account" and "cloning" means -"copying that code to your environment so you can work on it". - -#. Set up Git (Windows, Mac & Linux) -#. Go to the CodeIgniter repo -#. Fork it -#. Clone your CodeIgniter repo: git@github.com:/CodeIgniter.git -#. Checkout the "develop" branch At this point you are ready to start making - changes. -#. Fix existing bugs on the Issue tracker after taking a look to see nobody - else is working on them. -#. Commit the files -#. Push your develop branch to your fork -#. Send a pull request http://help.github.com/send-pull-requests/ - -The Reactor Engineers will now be alerted about the change and at least one of -the team will respond. If your change fails to meet the guidelines it will be -bounced, or feedback will be provided to help you improve it. - -Once the Reactor Engineer handling your pull request is happy with it they -will post it to the internal EllisLab discussion area to be double checked by -the other Engineers and EllisLab developers. If nobody has a problem with the -change then it will be merged into develop and will be part of the next -release. Keeping your fork up-to-date - -Unlike systems like Subversion, Git can have multiple remotes. A remote is the -name for a URL of a Git repository. By default your fork will have a remote -named "origin" which points to your fork, but you can add another remote named -"codeigniter" which points to git://github.com/EllisLab/CodeIgniter.git. This -is a read-only remote but you can pull from this develop branch to update your -own. - -If you are using command-line you can do the following: - -#. git remote add codeigniter git://github.com/EllisLab/CodeIgniter.git -#. git pull codeigniter develop -#. git push origin develop - -Now your fork is up to date. This should be done regularly, or before you send -a pull request at least. - ******* License ******* -- cgit v1.2.3-24-g4f1b From 628c77c28b62a0d564aee29cf7b12b338c0e7607 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Wed, 19 Sep 2012 16:29:30 +0100 Subject: Changed the contributing file to a markdown document as Github doesn't support rendering contributing file as rst Signed-off-by: Alex Bilbie --- contributing | 159 -------------------------------------------------------- contributing.md | 92 ++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+), 159 deletions(-) delete mode 100644 contributing create mode 100644 contributing.md diff --git a/contributing b/contributing deleted file mode 100644 index 0519b38cb..000000000 --- a/contributing +++ /dev/null @@ -1,159 +0,0 @@ -########################### -Contributing to CodeIgniter -########################### - -CodeIgniter is a community driven project and accepts contributions of code -and documentation from the community. These contributions are made in the form -of Issues or `Pull Requests `_ on -the `EllisLab CodeIgniter repository -`_ on GitHub. - -Issues are a quick way to point out a bug. If you find a bug or documentation -error in CodeIgniter then please check a few things first: - -- There is not already an open Issue -- The issue has already been fixed (check the develop branch, or look for - closed Issues) -- Is it something really obvious that you fix it yourself? - -Reporting issues is helpful but an even better approach is to send a Pull -Request, which is done by "Forking" the main repository and committing to your -own copy. This will require you to use the version control system called Git. - -********** -Guidelines -********** - -Before we look into how, here are the guidelines. If your Pull Requests fail -to pass these guidelines it will be declined and you will need to re-submit -when you’ve made the changes. This might sound a bit tough, but it is required -for us to maintain quality of the code-base. - -PHP Style -========= - -All code must meet the `Style Guide -`_, which is -essentially the `Allman indent style -`_, underscores and -readable operators. This makes certain that all code is the same format as the -existing code and means it will be as readable as possible. - -Documentation -============= - -If you change anything that requires a change to documentation then you will -need to add it. New classes, methods, parameters, changing default values, etc -are all things that will require a change to documentation. The change-log -must also be updated for every change. Also PHPDoc blocks must be maintained. - -Compatibility -============= - -CodeIgniter is compatible with PHP 5.2.4 so all code supplied must stick to -this requirement. If PHP 5.3 or 5.4 functions or features are used then there -must be a fallback for PHP 5.2.4. - -Branching -========= - -CodeIgniter uses the `Git-Flow -`_ branching model -which requires all pull requests to be sent to the "develop" branch. This is -where the next planned version will be developed. The "master" branch will -always contain the latest stable version and is kept clean so a "hotfix" (e.g: -an emergency security patch) can be applied to master to create a new version, -without worrying about other features holding it up. For this reason all -commits need to be made to "develop" and any sent to "master" will be closed -automatically. If you have multiple changes to submit, please place all -changes into their own branch on your fork. - -One thing at a time: A pull request should only contain one change. That does -not mean only one commit, but one change - however many commits it took. The -reason for this is that if you change X and Y but send a pull request for both -at the same time, we might really want X but disagree with Y, meaning we -cannot merge the request. Using the Git-Flow branching model you can create -new branches for both of these features and send two requests. - -Signing -======= -You must sign your work, certifying that you either wrote the work or -otherwise have the right to pass it on to an open source project. git makes -this trivial as you merely have to use `--signoff` on your commits to your -CodeIgniter fork. - -:: - - git commit --signoff - -or simply:: - - git commit -s - -This will sign your commits with the information setup in your git config, e.g. - - Signed-off-by: John Q Public - -If you are using Tower there is a "Sign-Off" checkbox in the commit window. You -could even alias git commit to use the -s flag so you don’t have to think about -it. - -By signing your work in this manner, you certify to a "Developer's Certificate -or Origin". The current version of this certificate is in the `DCO.txt` file -in the root of this repository. - - -************ -How-to Guide -************ - -There are two ways to make changes, the easy way and the hard way. Either way -you will need to `create a GitHub account `_. - -Easy way GitHub allows in-line editing of files for making simple typo changes -and quick-fixes. This is not the best way as you are unable to test the code -works. If you do this you could be introducing syntax errors, etc, but for a -Git-phobic user this is good for a quick-fix. - -Hard way The best way to contribute is to "clone" your fork of CodeIgniter to -your development area. That sounds like some jargon, but "forking" on GitHub -means "making a copy of that repo to your account" and "cloning" means -"copying that code to your environment so you can work on it". - -#. Set up Git (Windows, Mac & Linux) -#. Go to the CodeIgniter repo -#. Fork it -#. Clone your CodeIgniter repo: git@github.com:/CodeIgniter.git -#. Checkout the "develop" branch At this point you are ready to start making - changes. -#. Fix existing bugs on the Issue tracker after taking a look to see nobody - else is working on them. -#. Commit the files -#. Push your develop branch to your fork -#. Send a pull request http://help.github.com/send-pull-requests/ - -The Reactor Engineers will now be alerted about the change and at least one of -the team will respond. If your change fails to meet the guidelines it will be -bounced, or feedback will be provided to help you improve it. - -Once the Reactor Engineer handling your pull request is happy with it they -will post it to the internal EllisLab discussion area to be double checked by -the other Engineers and EllisLab developers. If nobody has a problem with the -change then it will be merged into develop and will be part of the next -release. Keeping your fork up-to-date - -Unlike systems like Subversion, Git can have multiple remotes. A remote is the -name for a URL of a Git repository. By default your fork will have a remote -named "origin" which points to your fork, but you can add another remote named -"codeigniter" which points to git://github.com/EllisLab/CodeIgniter.git. This -is a read-only remote but you can pull from this develop branch to update your -own. - -If you are using command-line you can do the following: - -#. git remote add codeigniter git://github.com/EllisLab/CodeIgniter.git -#. git pull codeigniter develop -#. git push origin develop - -Now your fork is up to date. This should be done regularly, or before you send -a pull request at least. \ No newline at end of file diff --git a/contributing.md b/contributing.md new file mode 100644 index 000000000..f3f94fbc8 --- /dev/null +++ b/contributing.md @@ -0,0 +1,92 @@ +# Contributing to CodeIgniter + + +CodeIgniter is a community driven project and accepts contributions of code and documentation from the community. These contributions are made in the form of Issues or [Pull Requests](http://help.github.com/send-pull-requests/) on the [EllisLab CodeIgniter repository](https://github.com/EllisLab/CodeIgniter>) on GitHub. + +Issues are a quick way to point out a bug. If you find a bug or documentation error in CodeIgniter then please check a few things first: + +1. There is not already an open Issue +2. The issue has already been fixed (check the develop branch, or look for closed Issues) +3. Is it something really obvious that you fix it yourself? + +Reporting issues is helpful but an even better approach is to send a Pull Request, which is done by "Forking" the main repository and committing to your own copy. This will require you to use the version control system called Git. + +## Guidelines + +Before we look into how, here are the guidelines. If your Pull Requests fail +to pass these guidelines it will be declined and you will need to re-submit +when you’ve made the changes. This might sound a bit tough, but it is required +for us to maintain quality of the code-base. + +### PHP Style + +All code must meet the [Style Guide](http://codeigniter.com/user_guide/general/styleguide.html), which is +essentially the [Allman indent style](http://en.wikipedia.org/wiki/Indent_style#Allman_style), underscores and readable operators. This makes certain that all code is the same format as the existing code and means it will be as readable as possible. + +### Documentation + +If you change anything that requires a change to documentation then you will need to add it. New classes, methods, parameters, changing default values, etc are all things that will require a change to documentation. The change-log must also be updated for every change. Also PHPDoc blocks must be maintained. + +### Compatibility + +CodeIgniter is compatible with PHP 5.2.4 so all code supplied must stick to +this requirement. If PHP 5.3 or 5.4 functions or features are used then there +must be a fallback for PHP 5.2.4. + +### Branching + +CodeIgniter uses the [Git-Flow](http://nvie.com/posts/a-successful-git-branching-model/) branching model which requires all pull requests to be sent to the "develop" branch. This is +where the next planned version will be developed. The "master" branch will always contain the latest stable version and is kept clean so a "hotfix" (e.g: an emergency security patch) can be applied to master to create a new version, without worrying about other features holding it up. For this reason all commits need to be made to "develop" and any sent to "master" will be closed automatically. If you have multiple changes to submit, please place all changes into their own branch on your fork. + +One thing at a time: A pull request should only contain one change. That does not mean only one commit, but one change - however many commits it took. The reason for this is that if you change X and Y but send a pull request for both at the same time, we might really want X but disagree with Y, meaning we cannot merge the request. Using the Git-Flow branching model you can create new branches for both of these features and send two requests. + +### Signing + +You must sign your work, certifying that you either wrote the work or otherwise have the right to pass it on to an open source project. git makes this trivial as you merely have to use `--signoff` on your commits to your CodeIgniter fork. + +`git commit --signoff` + +or simply + +`git commit -s` + +This will sign your commits with the information setup in your git config, e.g. + +`Signed-off-by: John Q Public ` + +If you are using [Tower](http://www.git-tower.com/) there is a "Sign-Off" checkbox in the commit window. You could even alias git commit to use the `-s` flag so you don’t have to think about it. + +By signing your work in this manner, you certify to a "Developer's Certificate of Origin". The current version of this certificate is in the `DCO.txt` file in the root of this repository. + + +## How-to Guide + +There are two ways to make changes, the easy way and the hard way. Either way you will need to [create a GitHub account](https://github.com/signup/free). + +Easy way GitHub allows in-line editing of files for making simple typo changes and quick-fixes. This is not the best way as you are unable to test the code works. If you do this you could be introducing syntax errors, etc, but for a Git-phobic user this is good for a quick-fix. + +Hard way The best way to contribute is to "clone" your fork of CodeIgniter to your development area. That sounds like some jargon, but "forking" on GitHub means "making a copy of that repo to your account" and "cloning" means "copying that code to your environment so you can work on it". + +1. Set up Git (Windows, Mac & Linux) +2. Go to the CodeIgniter repo +3. Fork it +4. Clone your CodeIgniter repo: git@github.com:/CodeIgniter.git +5. Checkout the "develop" branch At this point you are ready to start making changes. +6. Fix existing bugs on the Issue tracker after taking a look to see nobody else is working on them. +7. Commit the files +8. Push your develop branch to your fork +9. Send a pull request [http://help.github.com/send-pull-requests/](http://help.github.com/send-pull-requests/) + +The Reactor Engineers will now be alerted about the change and at least one of the team will respond. If your change fails to meet the guidelines it will be bounced, or feedback will be provided to help you improve it. + +Once the Reactor Engineer handling your pull request is happy with it they will post it to the internal EllisLab discussion area to be double checked by the other Engineers and EllisLab developers. If nobody has a problem with the change then it will be merged into develop and will be part of the next release. Keeping your fork up-to-date + +Unlike systems like Subversion, Git can have multiple remotes. A remote is the name for a URL of a Git repository. By default your fork will have a remote named "origin" which points to your fork, but you can add another remote named "codeigniter" which points to `git://github.com/EllisLab/CodeIgniter.git`. This is a read-only remote but you can pull from this develop branch to update your own. + +If you are using command-line you can do the following: + +1. `git remote add codeigniter git://github.com/EllisLab/CodeIgniter.git` +2. `git pull codeigniter develop` +3. `git push origin develop` + +Now your fork is up to date. This should be done regularly, or before you send a pull request at least. \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 14c9331420c960ff3237c2d82e34f7ebf8c6f12a Mon Sep 17 00:00:00 2001 From: Adam McCann Date: Thu, 20 Sep 2012 01:16:43 +0100 Subject: Fixes issue #1815 - input::ip_address() returns incorrect IP behind proxy --- system/core/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/core/Input.php b/system/core/Input.php index 968a42a9a..5b8e62389 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -383,7 +383,7 @@ class CI_Input { if (strpos($this->ip_address, ',') !== FALSE) { $x = explode(',', $this->ip_address); - $this->ip_address = trim(end($x)); + $this->ip_address = trim($x[0]); } if ( ! $this->valid_ip($this->ip_address)) -- cgit v1.2.3-24-g4f1b From 65bdaf5e2636cb7aa8780826529020ab0bfe9252 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 21 Sep 2012 13:49:09 +0800 Subject: Fixed pagination document error. Signed-off-by: Bo-Yi Wu --- user_guide_src/source/libraries/pagination.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst index 7d750bd23..00554c1c7 100644 --- a/user_guide_src/source/libraries/pagination.rst +++ b/user_guide_src/source/libraries/pagination.rst @@ -80,7 +80,7 @@ The number of "digit" links you would like before and after the selected page number. For example, the number 2 will place two digits on either side, as in the example links at the very top of this page. -$config['use_page_number'] = TRUE; +$config['use_page_numbers'] = TRUE; ================================== By default, the URI segment will use the starting index for the items -- cgit v1.2.3-24-g4f1b From 6b4e3624b9a33c144b3ab4aea7904d5919fcc306 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 21 Sep 2012 13:57:24 +0800 Subject: Fixed #1817 Pagination class error Signed-off-by: Bo-Yi Wu --- system/libraries/Pagination.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index 4fa605ca9..e1e729bb0 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -215,7 +215,8 @@ class CI_Pagination { // string. If post, add a trailing slash to the base URL if needed if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) { - $this->base_url = rtrim($this->base_url).'&'.$this->query_string_segment.'='; + $segment = (strpos($this->base_url, '?')) ? '&' : '?'; + $this->base_url = rtrim($this->base_url).$segment.$this->query_string_segment.'='; } else { -- cgit v1.2.3-24-g4f1b From a5e329ff95e0308c07b8db04117f056081997796 Mon Sep 17 00:00:00 2001 From: "W. Kristianto" Date: Sun, 23 Sep 2012 22:34:18 +0700 Subject: Update user_guide_src/source/libraries/loader.rst Remove the second parameter --- user_guide_src/source/libraries/loader.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/loader.rst b/user_guide_src/source/libraries/loader.rst index 33c1bafec..615aba1c2 100644 --- a/user_guide_src/source/libraries/loader.rst +++ b/user_guide_src/source/libraries/loader.rst @@ -344,6 +344,6 @@ calling add_package_path(). $this->load->remove_package_path(APPPATH.'my_app'); // Again without the second parameter: - $this->load->add_package_path(APPPATH.'my_app', TRUE); + $this->load->add_package_path(APPPATH.'my_app'); $this->load->view('my_app_index'); // Loads $this->load->view('welcome_message'); // Loads -- cgit v1.2.3-24-g4f1b From 50f7834a747242cbaa08b19bf8bb57dff02a4b23 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 2 Oct 2012 08:56:43 +0100 Subject: Added 'binary/octet-stream' as PDF mime. Fixes #1840 and #1828 Signed-off-by: Alex Bilbie --- application/config/mimes.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/mimes.php b/application/config/mimes.php index 48771dc15..af1c95ffd 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -49,7 +49,7 @@ return array( 'sea' => 'application/octet-stream', 'dll' => 'application/octet-stream', 'oda' => 'application/oda', - 'pdf' => array('application/pdf', 'application/x-download'), + 'pdf' => array('application/pdf', 'application/x-download', 'binary/octet-stream'), 'ai' => 'application/postscript', 'eps' => 'application/postscript', 'ps' => 'application/postscript', -- cgit v1.2.3-24-g4f1b From 7bd1690b8b1c74ee6d6ff3868525d8cdc0ec0803 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Tue, 2 Oct 2012 09:19:02 +0100 Subject: Added .dot and .dotx mimes. Fixes #1803 Signed-off-by: Alex Bilbie --- application/config/mimes.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/application/config/mimes.php b/application/config/mimes.php index af1c95ffd..90ffe61ff 100644 --- a/application/config/mimes.php +++ b/application/config/mimes.php @@ -124,6 +124,8 @@ return array( 'movie' => 'video/x-sgi-movie', 'doc' => array('application/msword', 'application/vnd.ms-office'), 'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'), + 'dot' => array('application/msword', 'application/vnd.ms-office'), + 'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'), 'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword'), 'word' => array('application/msword', 'application/octet-stream'), 'xl' => 'application/excel', -- cgit v1.2.3-24-g4f1b From a9923f5dc131f5a18175b1df3cf3f80a93ffb464 Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Wed, 3 Oct 2012 19:37:09 +0100 Subject: Support for hashing algorithms other than SHA1 and MD5 Signed-off-by: Daniel Morris --- system/libraries/Encrypt.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 8ffd93aea..3b04f7b06 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -484,7 +484,7 @@ class CI_Encrypt { */ public function set_hash($type = 'sha1') { - $this->_hash_type = ($type !== 'sha1' && $type !== 'md5') ? 'sha1' : $type; + $this->_hash_type = (in_array($type, hash_algos())) ? $type : 'sha1'; } // -------------------------------------------------------------------- @@ -497,7 +497,7 @@ class CI_Encrypt { */ public function hash($str) { - return ($this->_hash_type === 'sha1') ? sha1($str) : md5($str); + return hash($this->_hash_type, $str); } } -- cgit v1.2.3-24-g4f1b From c4a3c3cb01dcc5fbcd079313a8576c701f3f54ff Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Wed, 3 Oct 2012 14:34:37 -0700 Subject: Updated result function to check for visible items as defined in issue #395 --- system/libraries/Unit_test.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 70ad8dc41..435c32693 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -240,6 +240,11 @@ class CI_Unit_test { { foreach ($val as $k => $v) { + if ( ! in_array($k, $this->_test_items_visible)) + { + continue; + } + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; -- cgit v1.2.3-24-g4f1b From ada7775a47f32034ba589768612894c3cb6186ca Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Thu, 4 Oct 2012 10:24:16 +0100 Subject: Removed redundant parenthesis around `in_array()` --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 3b04f7b06..679609251 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -484,7 +484,7 @@ class CI_Encrypt { */ public function set_hash($type = 'sha1') { - $this->_hash_type = (in_array($type, hash_algos())) ? $type : 'sha1'; + $this->_hash_type = in_array($type, hash_algos()) ? $type : 'sha1'; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 824b4f220ca3dadc8f0945c665a7d7f8105a5dc4 Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Thu, 4 Oct 2012 10:25:03 +0100 Subject: Updated changelog to include changes to the Encryption library --- user_guide_src/source/changelog.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 73d9fb0ec..847b1be3e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -204,6 +204,8 @@ Release Date: Not Released - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments. - Removed the default `` `` from a number of the configuration variables. - Added the ability to use a proxy with the :doc:`XML-RPC Library `. + - :doc:`Encryption Library ` changes include: + - Added support for hashing algorithms other than SHA1 and MD5. - Core -- cgit v1.2.3-24-g4f1b From 2ea33c37e9bfa3ff0e029c18a0d2c9ef05016bf0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Oct 2012 12:37:51 +0300 Subject: Fix issue #1789 Signed-off-by: Andrey Andreev --- system/database/DB_driver.php | 4 ++++ system/database/drivers/cubrid/cubrid_driver.php | 6 ++---- system/database/drivers/ibase/ibase_driver.php | 4 ---- system/database/drivers/mssql/mssql_driver.php | 4 ---- system/database/drivers/mysql/mysql_driver.php | 4 ---- system/database/drivers/mysqli/mysqli_driver.php | 4 ---- system/database/drivers/oci8/oci8_driver.php | 4 ---- system/database/drivers/odbc/odbc_driver.php | 2 -- system/database/drivers/pdo/pdo_driver.php | 4 ---- system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php | 4 ---- system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php | 4 ---- system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php | 1 - system/database/drivers/postgre/postgre_driver.php | 4 ---- system/database/drivers/sqlite/sqlite_driver.php | 4 ---- system/database/drivers/sqlite3/sqlite3_driver.php | 4 ---- system/database/drivers/sqlsrv/sqlsrv_driver.php | 4 ---- user_guide_src/source/changelog.rst | 11 ++++++----- 17 files changed, 12 insertions(+), 60 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index e61af91b7..b64b977cb 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -79,6 +79,10 @@ abstract class CI_DB_driver { protected $_protect_identifiers = TRUE; protected $_reserved_identifiers = array('*'); // Identifiers that should NOT be escaped + // clause and character used for LIKE escape sequences + protected $_like_escape_str = " ESCAPE '%s' "; + protected $_like_escape_chr = '!'; + /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index a3d0287f5..28724e0e8 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -45,10 +45,6 @@ class CI_DB_cubrid_driver extends CI_DB { // The character used for escaping - no need in CUBRID protected $_escape_char = '`'; - // clause and character used for LIKE escape sequences - not used in CUBRID - protected $_like_escape_str = ''; - protected $_like_escape_chr = ''; - protected $_random_keyword = ' RAND()'; // database specific random keyword // CUBRID-specific properties @@ -72,6 +68,8 @@ class CI_DB_cubrid_driver extends CI_DB { } } + // -------------------------------------------------------------------- + /** * Non-persistent database connection * diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index c9027670d..f7811bf46 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -45,10 +45,6 @@ class CI_DB_ibase_driver extends CI_DB { // The character used to escape with protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - protected $_random_keyword = ' Random()'; // database specific random keyword // Keeps track of the resource for the current transaction diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 1714704a8..b4a1af7ba 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -45,10 +45,6 @@ class CI_DB_mssql_driver extends CI_DB { // The character used for escaping protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - protected $_random_keyword = ' NEWID()'; // MSSQL-specific properties diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 35473016f..6b4d84dfb 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -45,10 +45,6 @@ class CI_DB_mysql_driver extends CI_DB { // The character used for escaping protected $_escape_char = '`'; - // clause and character used for LIKE escape sequences - not used in MySQL - protected $_like_escape_str = ''; - protected $_like_escape_chr = '\\'; - protected $_random_keyword = ' RAND()'; // database specific random keyword /** diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 9558dfd86..453ddcc3f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -45,10 +45,6 @@ class CI_DB_mysqli_driver extends CI_DB { // The character used for escaping protected $_escape_char = '`'; - // clause and character used for LIKE escape sequences - not used in MySQL - protected $_like_escape_str = ''; - protected $_like_escape_chr = '\\'; - protected $_random_keyword = ' RAND()'; // database specific random keyword /** diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 691247fee..7bf18949b 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -54,10 +54,6 @@ class CI_DB_oci8_driver extends CI_DB { // The character used for excaping protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - /** * The syntax to count rows is slightly different across different * database engines, so this string appears in each driver and is diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 8f0a474b0..fbf6a4cb1 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -45,9 +45,7 @@ class CI_DB_odbc_driver extends CI_DB { // the character used to excape - not necessary for ODBC protected $_escape_char = ''; - // clause and character used for LIKE escape sequences protected $_like_escape_str = " {escape '%s'} "; - protected $_like_escape_chr = '!'; protected $_random_keyword; diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index 705b16560..0ffe3bc13 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -45,10 +45,6 @@ class CI_DB_pdo_driver extends CI_DB { // The character used to escaping protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - protected $_random_keyword; public $trans_enabled = FALSE; diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php index 05eeacfe6..eb3714783 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -44,10 +44,6 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver { protected $_escape_char = '`'; - // clause and character used for LIKE escape sequences - not used in CUBRID - protected $_like_escape_str = ''; - protected $_like_escape_chr = '\\'; - protected $_random_keyword = ' RAND()'; /** diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 78afe246c..b6807026d 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -44,10 +44,6 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { protected $_escape_char = '`'; - // clause and character used for LIKE escape sequences - not used in MySQL - protected $_like_escape_str = ''; - protected $_like_escape_chr = '\\'; - protected $_random_keyword = ' RAND()'; /** diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php index 392754ff7..dd7a1af52 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -46,7 +46,6 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver { protected $_escape_char = ''; // clause and character used for LIKE escape sequences - protected $_like_escape_chr = '!'; protected $_like_escape_str = " {escape '%s'} "; protected $_random_keyword = ' RAND()'; diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 8c11c477b..1d6e9567a 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -44,10 +44,6 @@ class CI_DB_postgre_driver extends CI_DB { protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - protected $_random_keyword = ' RANDOM()'; // database specific random keyword /** diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 19824dbbf..2744a63cf 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -45,10 +45,6 @@ class CI_DB_sqlite_driver extends CI_DB { // The character used to escape with - not needed for SQLite protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - protected $_random_keyword = ' Random()'; // database specific random keyword /** diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index cc35d319f..23145e7f9 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -46,10 +46,6 @@ class CI_DB_sqlite3_driver extends CI_DB { // The character used for escaping protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = ' ESCAPE \'%s\' '; - protected $_like_escape_chr = '!'; - protected $_random_keyword = ' RANDOM()'; /** diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index bda450e88..abcaf4577 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -45,10 +45,6 @@ class CI_DB_sqlsrv_driver extends CI_DB { // The character used for escaping protected $_escape_char = '"'; - // clause and character used for LIKE escape sequences - protected $_like_escape_str = " ESCAPE '%s' "; - protected $_like_escape_chr = '!'; - protected $_random_keyword = ' NEWID()'; // SQLSRV-specific properties diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 73d9fb0ec..dd0cb9e35 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -312,12 +312,12 @@ Bug fixes for 3.0 - Fixed a bug (#666) - :doc:`Output library `'s set_content_type() method didn't set the document charset. - Fixed a bug (#784, #861) - :doc:`Database Forge ` method ``create_table()`` used to accept constraints for MSSQL/SQLSRV integer-type columns. - Fixed a bug (#706) - SQLSRV/MSSSQL didn't escape field names. -- Fixed a bug (#1452) - protect_identifiers() didn't properly detect identifiers with spaces in their names. -- Fixed a bug where protect_identifiers() ignored it's extra arguments when the value passed to it is an array. -- Fixed a bug where _has_operator() didn't detect BETWEEN. -- Fixed a bug in :doc:`Query Builder `'s join() method where it failed with identifiers containing dashes. +- Fixed a bug (#1452) - ``protect_identifiers()`` didn't properly detect identifiers with spaces in their names. +- Fixed a bug where ``protect_identifiers()`` ignored it's extra arguments when the value passed to it is an array. +- Fixed a bug where ``_has_operator()`` didn't detect BETWEEN. +- Fixed a bug in :doc:`Query Builder `'s ``join()`` method where it failed with identifiers containing dashes. - Fixed a bug (#1264) - :doc:`Database Forge ` and :doc:`Database Utilities ` didn't update/reset the databases and tables list cache when a table or a database is created, dropped or renamed. -- Fixed a bug (#7) - :doc:`Query Builder `'s join() method only escaped one set of conditions. +- Fixed a bug (#7) - :doc:`Query Builder `'s ``join()`` method only escaped one set of conditions. - Fixed a bug (#1321) - Core Exceptions class couldn't find the errors/ folder in some cases. - Fixed a bug in the File-based :doc:`Cache Library ` driver's get_metadata() method where a non-existent array key was accessed for the TTL value. - Fixed a bug (#1202) - :doc:`Encryption Library ` encode_from_legacy() didn't set back the encrypt mode on failure. @@ -343,6 +343,7 @@ Bug fixes for 3.0 - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. - Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application. - Fixed a bug (#1757) - :doc:`Directory Helper ` function ``directory_map()`` was skipping files and directories named *0*. +- Fixed a bug (#1789) - :doc:`Database Library ` method ``escape_str()`` escaped quote characters in LIKE conditions twice under MySQL. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 13be5578e7ea440f4f33bc4c5c22096686224d66 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Oct 2012 12:43:03 +0300 Subject: Fix escape_like_str() tests --- tests/codeigniter/database/query_builder/escape_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/codeigniter/database/query_builder/escape_test.php b/tests/codeigniter/database/query_builder/escape_test.php index c6380ddf1..27e678f22 100644 --- a/tests/codeigniter/database/query_builder/escape_test.php +++ b/tests/codeigniter/database/query_builder/escape_test.php @@ -27,7 +27,7 @@ class Escape_test extends CI_TestCase { if (strpos(DB_DRIVER, 'mysql') !== FALSE) { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; } else { @@ -52,7 +52,7 @@ class Escape_test extends CI_TestCase { if (strpos(DB_DRIVER, 'mysql') !== FALSE) { - $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '';"; + $sql = "SELECT `value` FROM `misc` WHERE `key` LIKE '$string%' ESCAPE '!';"; } else { -- cgit v1.2.3-24-g4f1b From 5b92ae1dfb6ac99630693d193b0d3f60f9df525f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 4 Oct 2012 13:05:03 +0300 Subject: Misc. style fixes [ci skip] --- system/core/Input.php | 20 +++++++++------ user_guide_src/source/changelog.rst | 49 ++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/system/core/Input.php b/system/core/Input.php index 5b8e62389..657fce625 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -330,10 +330,10 @@ class CI_Input { if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) { - $has_ranges = strpos($proxies, '/') !== false; + $has_ranges = strpos($proxies, '/') !== FALSE; $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); $proxies = is_array($proxies) ? $proxies : array($proxies); - + if ($has_ranges) { $long_ip = ip2long($_SERVER['REMOTE_ADDR']); @@ -341,21 +341,25 @@ class CI_Input { // Go through each of the IP Addresses to check for and // test against range notation - foreach($proxies as $ip) + foreach ($proxies as $ip) { - list($address, $mask_length) = explode('/', $ip); + list($address, $mask_length) = explode('/', $ip, 2); // Generate the bitmask for a 32 bit IP Address - $bitmask = $bit_32 - (1 << (32 - (int)$mask_length)); - if (($long_ip & $bitmask) == $address) + $bitmask = $bit_32 - (1 << (32 - (int) $mask_length)); + if (($long_ip & $bitmask) === $address) { $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; break; } } - } else { - $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + } + else + { + $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) + ? $_SERVER['HTTP_X_FORWARDED_FOR'] + : $_SERVER['REMOTE_ADDR']; } } elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR')) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 4d7758659..912f8f8e9 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -145,7 +145,7 @@ Release Date: Not Released - Added capability for packages to hold database.php config files - Added subdrivers support (currently only used by PDO). - Added client compression support for MySQL and MySQLi. - - Removed :doc:`Loader Class ` from Database error to better find the likely culprit. + - Removed :doc:`Loader Class ` from Database error tracing to better find the likely culprit. - Libraries @@ -160,10 +160,12 @@ Release Date: Not Released - Changed the Cookie driver to select only one row when using database sessions. - Cookie driver now only writes to database at end of request when using database. - Cookie driver now uses PHP functions for faster array manipulation when using database. - - Added all_flashdata() method to session class. Returns an associative array of only flashdata. - - Added has_userdata() method to verify existence of userdata item. - - Added tempdata(), set_tempdata(), and unset_tempdata() methods for manipulating tempdata. - - Added max_filename_increment config setting for Upload library. + - Added ``all_flashdata()`` method to session class. Returns an associative array of only flashdata. + - Added ``has_userdata()`` method to verify existence of userdata item. + - Added ``tempdata()``, ``set_tempdata()``, and ``unset_tempdata()`` methods for manipulating tempdata. + - :doc:`File Uploading Library ` changes include: + - Added *max_filename_increment* config setting. + - Added an "index" parameter to the ``data()`` method. - :doc:`Cart library ` changes include: - It now auto-increments quantity's instead of just resetting it, this is the default behaviour of large e-commerce sites. - Product Name strictness can be disabled via the Cart Library by switching "$product_name_safe". @@ -174,9 +176,6 @@ Release Date: Not Released - Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method if they are set manually after initialization. - If property maintain_ratio is set to TRUE, image_reproportion() now doesn't need both width and height to be specified. - Property maintain_ratio is now taken into account when resizing images using ImageMagick library - - Removed SHA1 function in the :doc:`Encryption Library `. - - Added $config['csrf_regeneration'] to the CSRF protection in the :doc:`Security library `, which makes token regeneration optional. - - Added $config['csrf_exclude_uris'] to the CSRF protection in the :doc:`Security library `, which allows you list URIs which will not have the CSRF validation functions run. - :doc:`Form Validation library ` changes include: - Added method error_array() to return all error messages as an array. - Added method set_data() to set an alternative data array to be validated instead of the default $_POST. @@ -187,7 +186,7 @@ Release Date: Not Released - Native PHP functions used as rules can now accept an additional parameter, other than the data itself. - Updated set_rules() to accept an array of rules as well as a string. - Fields that have empty rules set no longer run through validation (and therefore are not considered erroneous). - - Allowed for setting table class defaults in a config file. + - Added support for setting :doc:`Table ` class defaults in a config file. - Added a Wincache driver to the :doc:`Caching Library `. - Added a Redis driver to the :doc:`Caching Library `. - :doc:`Email library ` changes include: @@ -196,7 +195,6 @@ Release Date: Not Released - Added dsn (delivery status notification) option. - Renamed method _set_header() to set_header() and made it public to enable adding custom headers in the :doc:`Email Library `. - Successfully sent emails will automatically clear the parameters. - - Added an "index" parameter to the data() method in the :doc:`Upload Library `. - :doc:`Pagination Library ` changes include: - Added support for the anchor "rel" attribute. - Added support for setting custom attributes. @@ -205,32 +203,37 @@ Release Date: Not Released - Removed the default `` `` from a number of the configuration variables. - Added the ability to use a proxy with the :doc:`XML-RPC Library `. - :doc:`Encryption Library ` changes include: - - Added support for hashing algorithms other than SHA1 and MD5. + - Added support for hashing algorithms other than SHA1 and MD5. + - Removed previously deprecated ``sha1()`` method. - Core - Changed private methods in the :doc:`URI Library ` to protected so MY_URI can override them. - - Removed CI_CORE boolean constant from CodeIgniter.php (no longer Reactor and Core versions). + - Removed ``CI_CORE`` boolean constant from CodeIgniter.php (no longer Reactor and Core versions). - :doc:`Loader Library ` changes include: - Added method get_vars() to the Loader to retrieve all variables loaded with $this->load->vars(). - CI_Loader::_ci_autoloader() is now a protected method. - Added autoloading of drivers with $autoload['drivers']. - CI_Loader::library() will now load drivers as well, for backward compatibility of converted libraries (like Session). - - is_loaded() function from system/core/Commons.php now returns a reference. + - ``is_loaded()`` function from *system/core/Commons.php* now returns a reference. - $config['rewrite_short_tags'] now has no effect when using PHP 5.4 as *` to retrieve $_SERVER['REQUEST_METHOD']. + - Added ``method()`` to the :doc:`Input Library ` to retrieve ``$_SERVER['REQUEST_METHOD']``. - 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). + - 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() method to the :doc:`Output Library `. - - Added get_mimes() function to system/core/Commons.php to return the config/mimes.php array. - - Added a second argument to set_content_type() in the :doc:`Output Library ` that allows setting the document charset as well. - - $config['time_reference'] now supports all timezone strings supported by PHP. - - Added support for HTTP code 303 ("See Other") in set_status_header(). - - Changed :doc:`Config Library ` method site_url() to accept an array as well. - - Added method ``strip_image_tags()`` to the :doc:`Security Library `. + - :doc:`Output Library ` 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 ``get_mimes()`` function to *system/core/Commons.php* to return the *config/mimes.php* array. + - ``$config['time_reference']`` now supports all timezone strings supported by PHP. + - Added support for HTTP code 303 ("See Other") in ``set_status_header()``. + - Changed :doc:`Config Library ` method ``site_url()`` to accept an array as well. + - :doc:`Security Library ` changes include: + - Added method ``strip_image_tags()``. + - Added ``$config['csrf_regeneration']``, which makes token regeneration optional. + - Added ``$config['csrf_exclude_uris']``, which allows you list URIs which will not have the CSRF validation methods run. - Changed ``_exception_handler()`` to respect php.ini 'display_errors' setting. - - Added support for IPv4 range masks (e.g. 192.168.1.1/24) to specify ranges of IP addresses for use with the proxy_ips setting. + - Added support for IPv4 range masks (e.g. 192.168.1.1/24) to specify ranges of IP addresses for use with the *proxy_ips* setting. Bug fixes for 3.0 ------------------ -- cgit v1.2.3-24-g4f1b From ddb32da0e86510d7e68c5432a1657732a01b5d34 Mon Sep 17 00:00:00 2001 From: Kyle Johnson Date: Thu, 4 Oct 2012 10:19:57 -0700 Subject: Updated changelog with bugfix (#395) Signed-off-by: Kyle Johnson --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 73d9fb0ec..98ab4aec1 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -343,6 +343,7 @@ Bug fixes for 3.0 - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. - Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application. - Fixed a bug (#1757) - :doc:`Directory Helper ` function ``directory_map()`` was skipping files and directories named *0*. +- Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns against _test_items_visible when called from ``report()`` method. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 6602cd7b7433b1d514b0f944cc9de563133174cf Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Thu, 4 Oct 2012 21:06:21 +0100 Subject: DRY determining server protocol Signed-off-by: Daniel Morris --- system/core/Common.php | 6 +----- user_guide_src/source/changelog.rst | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/system/core/Common.php b/system/core/Common.php index 57374b07d..09b73ef2e 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -488,13 +488,9 @@ if ( ! function_exists('set_status_header')) { header('Status: '.$code.' '.$text, TRUE); } - elseif ($server_protocol === 'HTTP/1.0') - { - header('HTTP/1.0 '.$code.' '.$text, TRUE, $code); - } else { - header('HTTP/1.1 '.$code.' '.$text, TRUE, $code); + header($server_protocol.' '.$code.' '.$text, TRUE, $code); } } } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 847b1be3e..378eec061 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -231,6 +231,7 @@ Release Date: Not Released - Added method ``strip_image_tags()`` to the :doc:`Security Library `. - Changed ``_exception_handler()`` to respect php.ini 'display_errors' setting. - Added support for IPv4 range masks (e.g. 192.168.1.1/24) to specify ranges of IP addresses for use with the proxy_ips setting. + - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()`` Bug fixes for 3.0 ------------------ -- cgit v1.2.3-24-g4f1b From e5f9e4a6069db57ec6c166bc8f198b1c229cf399 Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Thu, 4 Oct 2012 21:33:46 +0100 Subject: Default to HTTP/1.1 if $server_protocol is not set Signed-off-by: Daniel Morris --- system/core/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/core/Common.php b/system/core/Common.php index 09b73ef2e..2a804877d 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -490,7 +490,7 @@ if ( ! function_exists('set_status_header')) } else { - header($server_protocol.' '.$code.' '.$text, TRUE, $code); + header($server_protocol ?: 'HTTP/1.1'.' '.$code.' '.$text, TRUE, $code); } } } -- cgit v1.2.3-24-g4f1b From 7885c5cac9932e0598719682522b1c4902c15876 Mon Sep 17 00:00:00 2001 From: Daniel Morris Date: Thu, 4 Oct 2012 21:44:09 +0100 Subject: Compatibility with PHP 5.2.4 and enclosed ternary operation Signed-off-by: Daniel Morris --- system/core/Common.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/core/Common.php b/system/core/Common.php index 2a804877d..e449dd2e0 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -490,7 +490,7 @@ if ( ! function_exists('set_status_header')) } else { - header($server_protocol ?: 'HTTP/1.1'.' '.$code.' '.$text, TRUE, $code); + header(($server_protocol ? $server_protocol : 'HTTP/1.1').' '.$code.' '.$text, TRUE, $code); } } } -- cgit v1.2.3-24-g4f1b From 9438e26671ee1f0b49c8da7a56a0a195788fd5da Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 13:16:27 +0300 Subject: Fix issue #116 + other space/style fixes [ci skip --- system/core/Config.php | 2 +- system/core/Loader.php | 2 +- system/libraries/Unit_test.php | 2 +- user_guide_src/source/changelog.rst | 4 ++-- user_guide_src/source/libraries/image_lib.rst | 23 +++++++++++------------ 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/system/core/Config.php b/system/core/Config.php index 2f6a9e085..8e4f998ef 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -102,7 +102,7 @@ class CI_Config { { $file = ($file === '') ? 'config' : str_replace('.php', '', $file); $found = $loaded = FALSE; - + $check_locations = defined('ENVIRONMENT') ? array(ENVIRONMENT.'/'.$file, $file) : array($file); diff --git a/system/core/Loader.php b/system/core/Loader.php index 89b2028bf..75e93608a 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -1275,4 +1275,4 @@ class CI_Loader { } /* End of file Loader.php */ -/* Location: ./system/core/Loader.php */ +/* Location: ./system/core/Loader.php */ \ No newline at end of file diff --git a/system/libraries/Unit_test.php b/system/libraries/Unit_test.php index 435c32693..c2c01758e 100644 --- a/system/libraries/Unit_test.php +++ b/system/libraries/Unit_test.php @@ -244,7 +244,7 @@ class CI_Unit_test { { continue; } - + if (FALSE !== ($line = $CI->lang->line(strtolower('ut_'.$v)))) { $v = $line; diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index cafdf1083..e2f780c65 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -233,7 +233,7 @@ Release Date: Not Released - Added ``$config['csrf_regeneration']``, which makes token regeneration optional. - Added ``$config['csrf_exclude_uris']``, which allows you list URIs which will not have the CSRF validation methods run. - Changed ``_exception_handler()`` to respect php.ini 'display_errors' setting. - - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()`` + - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()``. - Added support for IPv4 range masks (e.g. 192.168.1.1/24) to specify ranges of IP addresses for use with the *proxy_ips* setting. Bug fixes for 3.0 @@ -349,8 +349,8 @@ Bug fixes for 3.0 - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. - Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application. - Fixed a bug (#1757) - :doc:`Directory Helper ` function ``directory_map()`` was skipping files and directories named *0*. -- Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns against _test_items_visible when called from ``report()`` method. - Fixed a bug (#1789) - :doc:`Database Library ` method ``escape_str()`` escaped quote characters in LIKE conditions twice under MySQL. +- Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns when called from ``report()``. Version 2.1.2 ============= diff --git a/user_guide_src/source/libraries/image_lib.rst b/user_guide_src/source/libraries/image_lib.rst index ed6575c62..dcdccbd92 100644 --- a/user_guide_src/source/libraries/image_lib.rst +++ b/user_guide_src/source/libraries/image_lib.rst @@ -91,9 +91,9 @@ error upon failure, like this:: echo $this->image_lib->display_errors(); } -Note: You can optionally specify the HTML formatting to be applied to -the errors, by submitting the opening/closing tags in the function, like -this:: +.. note:: You can optionally specify the HTML formatting to be applied to + the errors, by submitting the opening/closing tags in the function, + like this:: $this->image_lib->display_errors('

', '

'); @@ -225,8 +225,7 @@ pixels) specifying where to crop, like this:: $config['y_axis'] = '40'; All preferences listed in the table above are available for this -function except these: rotation_angle, width, height, create_thumb, -new_image. +function except these: rotation_angle, create_thumb, new_image. Here's an example showing how you might crop an image:: @@ -243,11 +242,11 @@ Here's an example showing how you might crop an image:: echo $this->image_lib->display_errors(); } -Note: Without a visual interface it is difficult to crop images, so this -function is not very useful unless you intend to build such an -interface. That's exactly what we did using for the photo gallery module -in ExpressionEngine, the CMS we develop. We added a JavaScript UI that -lets the cropping area be selected. +.. note:: Without a visual interface it is difficult to crop images, so this + function is not very useful unless you intend to build such an + interface. That's exactly what we did using for the photo gallery module + in ExpressionEngine, the CMS we develop. We added a JavaScript UI that + lets the cropping area be selected. $this->image_lib->rotate() =========================== @@ -338,8 +337,8 @@ The above example will use a 16 pixel True Type font to create the text bottom/center of the image, 20 pixels from the bottom of the image. .. note:: In order for the image class to be allowed to do any - processing, the image file must have "write" file permissions. For - example, 777. + processing, the image file must have "write" file permissions + For example, 777. Watermarking Preferences ======================== -- cgit v1.2.3-24-g4f1b From 740480a7513e29e201f56c6481067108a2031509 Mon Sep 17 00:00:00 2001 From: Dimitar Date: Fri, 5 Oct 2012 13:24:59 +0300 Subject: Bug-fix in XML-RPC library $type and $typeof are passed as strings in this function, therefore I took the easy way and simplified the validation. I tested with different requests (strings, numbers ..), no other issues found. --- system/libraries/Xmlrpc.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) mode change 100644 => 100755 system/libraries/Xmlrpc.php diff --git a/system/libraries/Xmlrpc.php b/system/libraries/Xmlrpc.php old mode 100644 new mode 100755 index a8aaa2088..dc5d27f8c --- a/system/libraries/Xmlrpc.php +++ b/system/libraries/Xmlrpc.php @@ -1317,15 +1317,15 @@ class XML_RPC_Values extends CI_Xmlrpc { $type = $type === '' ? 'string' : $type; - if ($this->xmlrpcTypes[$type] === 1) + if ($this->xmlrpcTypes[$type] == 1) { $this->addScalar($val,$type); } - elseif ($this->xmlrpcTypes[$type] === 2) + elseif ($this->xmlrpcTypes[$type] == 2) { $this->addArray($val); } - elseif ($this->xmlrpcTypes[$type] === 3) + elseif ($this->xmlrpcTypes[$type] == 3) { $this->addStruct($val); } @@ -1351,7 +1351,7 @@ class XML_RPC_Values extends CI_Xmlrpc return 0; } - if ($typeof !== 1) + if ($typeof != 1) { echo 'XML_RPC_Values: not a scalar type (${typeof})
'; return 0; -- cgit v1.2.3-24-g4f1b From 0af025841ac1acb05a79bf8758d7bf05d21ebd52 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 13:34:32 +0300 Subject: Manually apply pull #300 (fixes #295) [ci skip] --- application/views/errors/error_404.php | 8 +++++--- application/views/errors/error_db.php | 8 +++++--- application/views/errors/error_general.php | 8 +++++--- application/views/welcome_message.php | 13 +++++++------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/application/views/errors/error_404.php b/application/views/errors/error_404.php index c19bedfcd..fe48fd524 100644 --- a/application/views/errors/error_404.php +++ b/application/views/errors/error_404.php @@ -31,9 +31,9 @@ 404 Page Not Found -- cgit v1.2.3-24-g4f1b From 27482544315a4dd7a7bec18fef04b0c20436de15 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 14:51:12 +0300 Subject: Fix issue #935 [ci skip] --- system/language/english/form_validation_lang.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php index 021776161..cf1b3b503 100644 --- a/system/language/english/form_validation_lang.php +++ b/system/language/english/form_validation_lang.php @@ -43,8 +43,8 @@ $lang['integer'] = 'The %s field must contain an integer.'; $lang['regex_match'] = 'The %s field is not in the correct format.'; $lang['matches'] = 'The %s field does not match the %s field.'; $lang['is_unique'] = 'The %s field must contain a unique value.'; -$lang['is_natural'] = 'The %s field must contain only positive numbers.'; -$lang['is_natural_no_zero'] = 'The %s field must contain a number greater than zero.'; +$lang['is_natural'] = 'The %s field must only contain digits.'; +$lang['is_natural_no_zero'] = 'The %s field must only contain digits and must be greater than zero.'; $lang['decimal'] = 'The %s field must contain a decimal number.'; $lang['less_than'] = 'The %s field must contain a number less than %s.'; $lang['less_than_equal_to'] = 'The %s field must contain a number less than or equal to %s.'; -- cgit v1.2.3-24-g4f1b From 241a69be96de350b18d875304eb1e361b710e148 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 14:58:36 +0300 Subject: [ci skip] Add a note to the user guide regarding issue #1010 --- user_guide_src/source/libraries/form_validation.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 39f787402..faf221981 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -861,8 +861,9 @@ Rule Parameter Description ========================= ========== ============================================================================================= ======================= **required** No Returns FALSE if the form element is empty. **matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item] -**is_unique** Yes Returns FALSE if the form element is not unique to the is_unique[table.field] - table and field name in the parameter. is_unique[table.field] +**is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field] + parameter. Note: This rule requires :doc:`Query Builder ` to be + enabled in order to work. **max_length** Yes Returns FALSE if the form element is longer then the parameter value. max_length[12] **exact_length** Yes Returns FALSE if the form element is not exactly the parameter value. exact_length[8] **greater_than** Yes Returns FALSE if the form element is less than or equal to the parameter value or not greater_than[8] -- cgit v1.2.3-24-g4f1b From 99ae226607fff411bae3b69475bd1b0e3981d563 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 15:14:30 +0300 Subject: Add PNG transparency support in CI_Image_lib::text_watermark() (originally from pull #1317, partially fixes #1139) --- system/libraries/Image_lib.php | 7 +++++++ user_guide_src/source/changelog.rst | 9 +++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/system/libraries/Image_lib.php b/system/libraries/Image_lib.php index 899b995d4..ef4187847 100644 --- a/system/libraries/Image_lib.php +++ b/system/libraries/Image_lib.php @@ -1320,6 +1320,13 @@ class CI_Image_lib { imagestring($src_img, $this->wm_font_size, $x_shad, $y_shad, $this->wm_text, $drp_color); imagestring($src_img, $this->wm_font_size, $x_axis, $y_axis, $this->wm_text, $txt_color); } + + // We can preserve transparency for PNG images + if ($this->image_type === 3) + { + imagealphablending($src_img, FALSE); + imagesavealpha($src_img, TRUE); + } } // Output the final image diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index e2f780c65..b3fbe718b 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -172,10 +172,11 @@ Release Date: Not Released - Added function remove() to remove a cart item, updating with quantity of 0 seemed like a hack but has remained to retain compatibility. - :doc:`Image Manipulation library ` changes include: - The initialize() method now only sets existing class properties. - - Added support for 3-length hex color values for wm_font_color and wm_shadow_color properties, as well as validation for them. - - Class properties wm_font_color, wm_shadow_color and wm_use_drop_shadow are now protected, to avoid breaking the text_watermark() method if they are set manually after initialization. - - If property maintain_ratio is set to TRUE, image_reproportion() now doesn't need both width and height to be specified. - - Property maintain_ratio is now taken into account when resizing images using ImageMagick library + - Added support for 3-length hex color values for *wm_font_color* and *wm_shadow_color* properties, as well as validation for them. + - Class properties *wm_font_color*, *wm_shadow_color* and *wm_use_drop_shadow* are now protected, to avoid breaking the ``text_watermark()`` method if they are set manually after initialization. + - If property *maintain_ratio* is set to TRUE, ``image_reproportion()`` now doesn't need both width and height to be specified. + - Property *maintain_ratio* is now taken into account when resizing images using ImageMagick library. + - Added support for maintaining transparency for PNG images in method ``text_watermark()``. - :doc:`Form Validation library ` changes include: - Added method error_array() to return all error messages as an array. - Added method set_data() to set an alternative data array to be validated instead of the default $_POST. -- cgit v1.2.3-24-g4f1b From 327e4f7376749f4fe7f0fadb56bd925dc721463a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 15:44:43 +0300 Subject: [ci skip] Fix up the cheatsheets page (original pull #1244) --- .../images/codeigniter_1.7.1_library_reference.png | Bin 111744 -> 111747 bytes user_guide_src/source/overview/cheatsheets.rst | 15 +++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png b/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png index 554ae2eed..7f054f95f 100644 Binary files a/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png and b/user_guide_src/source/images/codeigniter_1.7.1_library_reference.png differ diff --git a/user_guide_src/source/overview/cheatsheets.rst b/user_guide_src/source/overview/cheatsheets.rst index 2e277aa9a..80c3112c4 100644 --- a/user_guide_src/source/overview/cheatsheets.rst +++ b/user_guide_src/source/overview/cheatsheets.rst @@ -5,12 +5,19 @@ CodeIgniter Cheatsheets Library Reference ================= -`|CodeIgniter Library -Reference| <../images/codeigniter_1.7.1_library_reference.pdf>`_ +|CodeIgniter Library Reference| + +- :download:`Download PDF <../images/codeigniter_1.7.1_library_reference.pdf>` + Helpers Reference ================= -`|image1| <../images/codeigniter_1.7.1_helper_reference.pdf>`_ +|CodeIgniter Helper Reference| + +- :download:`Download PDF <../images/codeigniter_1.7.1_helper_reference.pdf>` + .. |CodeIgniter Library Reference| image:: ../images/codeigniter_1.7.1_library_reference.png -.. |image1| image:: ../images/codeigniter_1.7.1_helper_reference.png + :target: ../_downloads/codeigniter_1.7.1_library_reference.pdf +.. |CodeIgniter Helper Reference| image:: ../images/codeigniter_1.7.1_helper_reference.png + :target: ../_downloads/codeigniter_1.7.1_helper_reference.pdf -- cgit v1.2.3-24-g4f1b From 6123b61e8ec95ac91f67bfbf442e34021c922319 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 15:54:43 +0300 Subject: Fix issue #1340 [ci skip] --- user_guide_src/source/libraries/file_uploading.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/user_guide_src/source/libraries/file_uploading.rst b/user_guide_src/source/libraries/file_uploading.rst index 65cd5c722..1698dcbb9 100644 --- a/user_guide_src/source/libraries/file_uploading.rst +++ b/user_guide_src/source/libraries/file_uploading.rst @@ -197,6 +197,7 @@ Preference Default Value Options Descripti Separate multiple types with a pipe. **file_name** None Desired file name If set CodeIgniter will rename the uploaded file to this name. The extension provided in the file name must also be an allowed file type. + If no extension is provided in the original file_name will be used. **overwrite** FALSE TRUE/FALSE (boolean) If set to true, if a file with the same name as the one you are uploading exists, it will be overwritten. If set to false, a number will be appended to the filename if another with the same name exists. -- cgit v1.2.3-24-g4f1b From 1194ad733135214e9905123258df3600b01735fd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 17:05:46 +0300 Subject: Fix issue #1692 --- system/database/DB_driver.php | 10 ++++++++-- user_guide_src/source/changelog.rst | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b64b977cb..acba9c187 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1348,7 +1348,7 @@ abstract class CI_DB_driver { } else { - $message = ( ! is_array($error)) ? array(str_replace('%s', $swap, $LANG->line($error))) : $error; + $message = is_array($error) ? $error : array(str_replace('%s', $swap, $LANG->line($error))); } // Find the most likely culprit of the error by going through @@ -1357,7 +1357,13 @@ abstract class CI_DB_driver { $trace = debug_backtrace(); foreach ($trace as $call) { - if (isset($call['file'], $call['class']) && strpos($call['file'], BASEPATH.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE) + // We'll need this on Windows, as APPPATH and BASEPATH will always use forward slashes + if (DIRECTORY_SEPARATOR !== '/') + { + $call['file'] = str_replace('\\', '/', $call['file']); + } + + if (isset($call['file'], $call['class']) && strpos($call['file'], $basepath.'database') === FALSE && strpos($call['class'], 'Loader') !== FALSE) { // Found it - use a relative path for safety $message[] = 'Filename: '.str_replace(array(APPPATH, BASEPATH), '', $call['file']); diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index b3fbe718b..5cfd795b1 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -350,8 +350,9 @@ Bug fixes for 3.0 - Fixed a bug in SQLSRV's ``affected_rows()`` method where an erroneous function name was used. - Fixed a bug (#1000) - Change syntax of ``$view_file`` to ``$_ci_view_file`` to prevent being overwritten by application. - Fixed a bug (#1757) - :doc:`Directory Helper ` function ``directory_map()`` was skipping files and directories named *0*. -- Fixed a bug (#1789) - :doc:`Database Library ` method ``escape_str()`` escaped quote characters in LIKE conditions twice under MySQL. -- Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns when called from ``report()``. +- Fixed a bug (#1789) - :doc:`Database Library ` method ``escape_str()`` escaped quote characters in LIKE conditions twice under MySQL. +- Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns when called from ``report()``. +- Fixed a bug (#1692) - :doc:`Database Library ` method ``display_error()`` didn't properly trace the possible error source on Windows systems. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From ccd01c75f5802e4e4b74bb53414a58d2aa0fd0d8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 17:12:55 +0300 Subject: Polish changes from #1586 --- system/libraries/Email.php | 4 ++-- user_guide_src/source/changelog.rst | 2 +- user_guide_src/source/libraries/email.rst | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 84ea1654b..4776df498 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -198,7 +198,7 @@ class CI_Email { if ($this->validate) { $this->validate_email($this->_str_to_array($from)); - if($return_path) + if ($return_path) { $this->validate_email($this->_str_to_array($return_path)); } @@ -221,7 +221,7 @@ class CI_Email { $this->set_header('From', $name.' <'.$from.'>'); - if(!$return_path) + if( ! $return_path) { $return_path = $from; } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 5b123b929..ff7229243 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -196,7 +196,7 @@ Release Date: Not Released - Added dsn (delivery status notification) option. - Renamed method _set_header() to set_header() and made it public to enable adding custom headers in the :doc:`Email Library `. - Successfully sent emails will automatically clear the parameters. - - Added third parameter $return_path in method Email::from(). + - Added a *return_path* parameter to the ``from()`` method. - :doc:`Pagination Library ` changes include: - Added support for the anchor "rel" attribute. - Added support for setting custom attributes. diff --git a/user_guide_src/source/libraries/email.rst b/user_guide_src/source/libraries/email.rst index fc324ffc9..e7ed9f74c 100644 --- a/user_guide_src/source/libraries/email.rst +++ b/user_guide_src/source/libraries/email.rst @@ -117,12 +117,12 @@ Sets the email address and name of the person sending the email:: $this->email->from('you@example.com', 'Your Name'); -:: +You can also set a Return-Path, to help redirect undelivered mail:: $this->email->from('you@example.com', 'Your Name', 'returned_emails@example.com'); -Third parameter is redirect for undelivered emails (may not be configured with -protocol 'smtp'). +.. note:: Return-Path can't be used if you've configured + 'smtp' as your protocol. $this->email->reply_to() ------------------------- -- cgit v1.2.3-24-g4f1b From 9e31f8f1600c6577f46a855eee6a3c7d527aebea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 17:31:46 +0300 Subject: Fix #1745 --- system/database/DB_driver.php | 2 +- user_guide_src/source/changelog.rst | 3 ++- user_guide_src/source/libraries/form_validation.rst | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index acba9c187..b12042bde 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -674,7 +674,7 @@ abstract class CI_DB_driver { */ public function is_write_type($sql) { - return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD DATA|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql); + return (bool) preg_match('/^\s*"?(SET|INSERT|UPDATE|DELETE|REPLACE|CREATE|DROP|TRUNCATE|LOAD|COPY|ALTER|RENAME|GRANT|REVOKE|LOCK|UNLOCK|REINDEX)\s+/i', $sql); } // -------------------------------------------------------------------- diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index ff7229243..4c3133e92 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -271,7 +271,7 @@ Bug fixes for 3.0 - Fixed a bug (#129) - ODBC's num_rows() returned -1 in some cases, due to not all subdrivers supporting the odbc_num_rows() function. - Fixed a bug (#153) - E_NOTICE being generated by getimagesize() in the :doc:`File Uploading Library `. - Fixed a bug (#611) - SQLSRV's error handling methods used to issue warnings when there's no actual error. -- Fixed a bug (#1036) - is_write_type() method in the :doc:`Database Library ` didn't return TRUE for RENAME queries. +- Fixed a bug (#1036) - ``is_write_type()`` method in the :doc:`Database Library ` didn't return TRUE for RENAME queries. - Fixed a bug in PDO's _version() method where it used to return the client version as opposed to the server one. - Fixed a bug in PDO's insert_id() method where it could've failed if it's used with Postgre versions prior to 8.1. - Fixed a bug in CUBRID's affected_rows() method where a connection resource was passed to cubrid_affected_rows() instead of a result. @@ -354,6 +354,7 @@ Bug fixes for 3.0 - Fixed a bug (#1789) - :doc:`Database Library ` method ``escape_str()`` escaped quote characters in LIKE conditions twice under MySQL. - Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns when called from ``report()``. - Fixed a bug (#1692) - :doc:`Database Library ` method ``display_error()`` didn't properly trace the possible error source on Windows systems. +- Fixed a bug (#1745) - ``is_write_type()`` method in the :doc:`Database Library ` didn't return TRUE for LOAD queries. Version 2.1.2 ============= diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 29e1be032..bc922e69b 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -489,11 +489,13 @@ the name of the function:: $this->form_validation->set_message('username_check') If you are using an error message that can accept two $s in your error string, -such as .. +such as: +:: $this->form_validation->set_message('min_length', 'The $s field must contain at least $s characters.'); Then you can also use %1$s and %2$s: +:: $this->form_validation->set_message('min_length', 'This field must contain at least %2$s characters.'); -- cgit v1.2.3-24-g4f1b From ebbfefafb4498c2b84eb2c4608d7c97da10b1b09 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 17:46:47 +0300 Subject: Fix SQLite3 DB error handling --- system/database/drivers/sqlite3/sqlite3_driver.php | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index 23145e7f9..d03be15f5 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -284,25 +284,16 @@ class CI_DB_sqlite3_driver extends CI_DB { // -------------------------------------------------------------------- /** - * The error message string + * Error * - * @return string - */ - protected function _error_message() - { - return $this->conn_id->lastErrorMsg(); - } - - // -------------------------------------------------------------------- - - /** - * The error message number + * Returns an array containing code and message of the last + * database error that has occured. * - * @return int + * @return array */ - protected function _error_number() + public function error() { - return $this->conn_id->lastErrorCode(); + return array('code' => $this->conn_id->lastErrorCode(), 'message' => $this->conn_id->lastErrorMsg()); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 73766c239318974b7e8ed02ab441794cab7f523f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 20:32:14 +0300 Subject: [ci skip] Small doc fixes, thanks dchill42 --- user_guide_src/source/changelog.rst | 2 +- user_guide_src/source/libraries/pagination.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 4c3133e92..5a8036128 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -163,7 +163,7 @@ Release Date: Not Released - Added ``all_flashdata()`` method to session class. Returns an associative array of only flashdata. - Added ``has_userdata()`` method to verify existence of userdata item. - Added ``tempdata()``, ``set_tempdata()``, and ``unset_tempdata()`` methods for manipulating tempdata. - - :doc:`File Uploading Library ` changes include: + - :doc:`File Uploading Library ` changes include: - Added *max_filename_increment* config setting. - Added an "index" parameter to the ``data()`` method. - :doc:`Cart library ` changes include: diff --git a/user_guide_src/source/libraries/pagination.rst b/user_guide_src/source/libraries/pagination.rst index 00554c1c7..d9d3f5092 100644 --- a/user_guide_src/source/libraries/pagination.rst +++ b/user_guide_src/source/libraries/pagination.rst @@ -81,7 +81,7 @@ page number. For example, the number 2 will place two digits on either side, as in the example links at the very top of this page. $config['use_page_numbers'] = TRUE; -================================== +=================================== By default, the URI segment will use the starting index for the items you are paginating. If you prefer to show the the actual page number, -- cgit v1.2.3-24-g4f1b From 92f00046751d44b3e938d6be1fc49017dd0e0040 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 20:43:36 +0300 Subject: [ci skip] More doc fixes --- user_guide_src/source/changelog.rst | 2 +- user_guide_src/source/libraries/form_validation.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 5a8036128..1311c7fc0 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -204,7 +204,7 @@ Release Date: Not Released - Added $config['reuse_query_string'] to allow automatic repopulation of query string arguments, combined with normal URI segments. - Removed the default `` `` from a number of the configuration variables. - Added the ability to use a proxy with the :doc:`XML-RPC Library `. - - :doc:`Encryption Library ` changes include: + - :doc:`Encryption Library ` changes include: - Added support for hashing algorithms other than SHA1 and MD5. - Removed previously deprecated ``sha1()`` method. diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index bc922e69b..14305b664 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -873,7 +873,7 @@ Rule Parameter Description **required** No Returns FALSE if the form element is empty. **matches** Yes Returns FALSE if the form element does not match the one in the parameter. matches[form_item] **is_unique** Yes Returns FALSE if the form element is not unique to the table and field name in the is_unique[table.field] - parameter. Note: This rule requires :doc:`Query Builder ` to be + parameter. Note: This rule requires :doc:`Query Builder <../database/query_builder>` to be enabled in order to work. **max_length** Yes Returns FALSE if the form element is longer then the parameter value. max_length[12] **exact_length** Yes Returns FALSE if the form element is not exactly the parameter value. exact_length[8] -- cgit v1.2.3-24-g4f1b From 6775a79ffdb4501ae8a3d88968d9531607ccab14 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 20:54:12 +0300 Subject: [ci skip] Add Vietnamese characters to foreign_chars.php --- application/config/foreign_chars.php | 24 ++++++++++++------------ user_guide_src/source/changelog.rst | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/application/config/foreign_chars.php b/application/config/foreign_chars.php index 41de123da..6614caa31 100644 --- a/application/config/foreign_chars.php +++ b/application/config/foreign_chars.php @@ -40,20 +40,20 @@ $foreign_characters = array( '/Ä/' => 'Ae', '/Ü/' => 'Ue', '/Ö/' => 'Oe', - '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά/' => 'A', - '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά/' => 'a', + '/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ/' => 'A', + '/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ/' => 'a', '/Ç|Ć|Ĉ|Ċ|Č/' => 'C', '/ç|ć|ĉ|ċ|č/' => 'c', '/Ð|Ď|Đ|Δ/' => 'Dj', '/ð|ď|đ|δ/' => 'dj', - '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ/' => 'E', - '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε/' => 'e', + '/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ/' => 'E', + '/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ/' => 'e', '/Ĝ|Ğ|Ġ|Ģ|Γ/' => 'G', '/ĝ|ğ|ġ|ģ|γ/' => 'g', '/Ĥ|Ħ/' => 'H', '/ĥ|ħ/' => 'h', - '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ/' => 'I', - '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ/' => 'i', + '/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị/' => 'I', + '/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị/' => 'i', '/Ĵ/' => 'J', '/ĵ/' => 'j', '/Ķ|Κ/' => 'K', @@ -62,18 +62,18 @@ $foreign_characters = array( '/ĺ|ļ|ľ|ŀ|ł|λ/' => 'l', '/Ñ|Ń|Ņ|Ň|Ν/' => 'N', '/ñ|ń|ņ|ň|ʼn|ν/' => 'n', - '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ/' => 'O', - '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ/' => 'o', + '/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ/' => 'O', + '/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ/' => 'o', '/Ŕ|Ŗ|Ř|Ρ/' => 'R', '/ŕ|ŗ|ř|ρ/' => 'r', '/Ś|Ŝ|Ş|Ș|Š|Σ/' => 'S', '/ś|ŝ|ş|ș|š|ſ|σ|ς/' => 's', '/Ț|Ţ|Ť|Ŧ|τ/' => 'T', '/ț|ţ|ť|ŧ/' => 't', - '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ/' => 'U', - '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ/' => 'u', - '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ/' => 'Y', - '/ý|ÿ|ŷ/' => 'y', + '/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự/' => 'U', + '/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự/' => 'u', + '/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ/' => 'Y', + '/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ/' => 'y', '/Ŵ/' => 'W', '/ŵ/' => 'w', '/Ź|Ż|Ž|Ζ/' => 'Z', diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 1311c7fc0..62992d25b 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -39,7 +39,7 @@ Release Date: Not Released - Updated support for zip files in mimes.php. - Updated support for csv files in mimes.php. - Added some more doctypes. - - Added Romanian and Greek characters in foreign_characters.php. + - Added Romanian, Greek and Vietnamese characters in *foreign_characters.php*. - Changed logger to only chmod when file is first created. - Removed previously deprecated SHA1 Library. - Removed previously deprecated use of ``$autoload['core']`` in application/config/autoload.php. -- cgit v1.2.3-24-g4f1b From dbad54e09a39a77c7404dee9ca1a6b34299469d0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 21:53:32 +0300 Subject: Fix issue #1765 --- system/database/drivers/mysqli/mysqli_driver.php | 12 ++++++++++-- user_guide_src/source/changelog.rst | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 453ddcc3f..14949ecda 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -66,8 +66,8 @@ class CI_DB_mysqli_driver extends CI_DB { { $port = empty($this->port) ? NULL : $this->port; - $mysqli = mysqli_init(); - $mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); + $mysqli = new mysqli(); + @$mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); return $mysqli; } @@ -418,6 +418,14 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function error() { + if ( ! empty($this->conn_id->connect_errno)) + { + return array( + 'code' => $this->conn_id->connect_errno, + 'message' => is_php('5.2.9') ? $this->conn_id->connect_error : mysqli_connect_error() + ); + } + return array('code' => $this->conn_id->errno, 'message' => $this->conn_id->error); } diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 62992d25b..40ba218a8 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -355,6 +355,7 @@ Bug fixes for 3.0 - Fixed a bug (#395) - :doc:`Unit Testing Library ` method ``result()`` didn't properly check array result columns when called from ``report()``. - Fixed a bug (#1692) - :doc:`Database Library ` method ``display_error()`` didn't properly trace the possible error source on Windows systems. - Fixed a bug (#1745) - ``is_write_type()`` method in the :doc:`Database Library ` didn't return TRUE for LOAD queries. +- Fixed a bug (#1765) - :doc:`Database Library ` didn't properly detect connection errors for MySQLi. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From c60c2bd1ab70903ed3c1d12692aa5dd246f1c583 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 22:46:28 +0300 Subject: Remove an empty line --- user_guide_src/source/helpers/date_helper.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index d0c72c3c4..9de925ba7 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -485,4 +485,4 @@ UP12 (UTC +12:00) Fiji, Gilbert Islands, Kamchatka, New Zealand UP1275 (UTC +12:45) Chatham Islands Standard Time UP1 (UTC +13:00) Phoenix Islands Time, Tonga UP14 (UTC +14:00) Line Islands -=========== ===================================================================== +=========== ===================================================================== \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 0df3585eec575d2d2e7d17c5339ed219a33dfde8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 5 Oct 2012 23:10:23 +0300 Subject: Add unit test --- tests/codeigniter/helpers/date_helper_test.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/codeigniter/helpers/date_helper_test.php b/tests/codeigniter/helpers/date_helper_test.php index 1b79b9480..9feade71c 100644 --- a/tests/codeigniter/helpers/date_helper_test.php +++ b/tests/codeigniter/helpers/date_helper_test.php @@ -290,6 +290,29 @@ class Date_helper_test extends CI_TestCase { $this->assertEquals(0, timezones('non_existant')); } + // ------------------------------------------------------------------------ + + public function test_date_range() + { + $dates = array( + '29-01-2012', '30-01-2012', '31-01-2012', + '01-02-2012', '02-02-2012', '03-02-2012', + '04-02-2012', '05-02-2012', '06-02-2012', + '07-02-2012', '08-02-2012', '09-02-2012', + '10-02-2012', '11-02-2012', '12-02-2012', + '13-02-2012', '14-02-2012', '15-02-2012', + '16-02-2012', '17-02-2012', '18-02-2012', + '19-02-2012', '20-02-2012', '21-02-2012', + '22-02-2012', '23-02-2012', '24-02-2012', + '25-02-2012', '26-02-2012', '27-02-2012', + '28-02-2012', '29-02-2012', '01-03-2012' + ); + + $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), mktime(12, 0, 0, 3, 1, 2012), TRUE, 'd-m-Y')); + array_pop($dates); + $this->assertEquals($dates, date_range(mktime(12, 0, 0, 1, 29, 2012), 31, FALSE, 'd-m-Y')); + } + } /* End of file date_helper_test.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 956631d2b8f0f1173f55134b8465b41d2018edfa Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 6 Oct 2012 20:43:47 +0300 Subject: [ci skip] Alter some changelog entries --- user_guide_src/source/changelog.rst | 11 ++++++----- user_guide_src/source/libraries/output.rst | 3 +++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 486a67696..87b01743e 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -218,7 +218,12 @@ Release Date: Not Released - CI_Loader::_ci_autoloader() is now a protected method. - Added autoloading of drivers with $autoload['drivers']. - CI_Loader::library() will now load drivers as well, for backward compatibility of converted libraries (like Session). - - ``is_loaded()`` function from *system/core/Commons.php* now returns a reference. + - :doc:`Common functions ` changes include: + - ``is_loaded()`` function now returns a reference. + - Added ``get_mimes()`` function to return the *config/mimes.php* array. + - Added support for HTTP code 303 ("See Other") in ``set_status_header()``. + - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()``. + - Changed ``_exception_handler()`` to respect php.ini *display_errors* setting. - $config['rewrite_short_tags'] now has no effect when using PHP 5.4 as *` to retrieve ``$_SERVER['REQUEST_METHOD']``. - Modified valid_ip() to use PHP's filter_var() in the :doc:`Input Library `. @@ -227,16 +232,12 @@ Release Date: Not Released - :doc:`Output Library ` 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 ``get_mimes()`` function to *system/core/Commons.php* to return the *config/mimes.php* array. - ``$config['time_reference']`` now supports all timezone strings supported by PHP. - - Added support for HTTP code 303 ("See Other") in ``set_status_header()``. - Changed :doc:`Config Library ` method ``site_url()`` to accept an array as well. - :doc:`Security Library ` changes include: - Added method ``strip_image_tags()``. - Added ``$config['csrf_regeneration']``, which makes token regeneration optional. - Added ``$config['csrf_exclude_uris']``, which allows you list URIs which will not have the CSRF validation methods run. - - Changed ``_exception_handler()`` to respect php.ini 'display_errors' setting. - - Removed redundant conditional to determine HTTP server protocol in ``set_status_header()``. - Added support for IPv4 range masks (e.g. 192.168.1.1/24) to specify ranges of IP addresses for use with the *proxy_ips* setting. Bug fixes for 3.0 diff --git a/user_guide_src/source/libraries/output.rst b/user_guide_src/source/libraries/output.rst index 0472d14cf..3289a241f 100644 --- a/user_guide_src/source/libraries/output.rst +++ b/user_guide_src/source/libraries/output.rst @@ -105,6 +105,9 @@ Permits you to manually set a server status header. Example:: `See here `_ for a full list of headers. +.. note:: This method is an alias for :doc:`Common function <../general/common_funtions.rst>` + ``set_status_header()``. + $this->output->enable_profiler(); ================================== -- cgit v1.2.3-24-g4f1b From cd50592b26a26a2e55fc193529a2463d9a465378 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 6 Oct 2012 21:27:01 +0300 Subject: Fix issue #1257 --- system/database/DB_query_builder.php | 20 +------------------- system/database/drivers/ibase/ibase_driver.php | 16 ---------------- system/database/drivers/mssql/mssql_driver.php | 16 ---------------- system/database/drivers/oci8/oci8_driver.php | 16 ---------------- system/database/drivers/odbc/odbc_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_4d_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_firebird_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_ibm_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_informix_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_oci_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_odbc_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_pgsql_driver.php | 16 ---------------- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 16 ---------------- system/database/drivers/postgre/postgre_driver.php | 16 ---------------- system/database/drivers/sqlsrv/sqlsrv_driver.php | 16 ---------------- user_guide_src/source/changelog.rst | 1 + 17 files changed, 2 insertions(+), 259 deletions(-) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 479b7f24a..8bd2ab53c 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1521,24 +1521,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This public function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - is_array($tables) OR $tables = array($tables); - - return (count($tables) === 1) ? $tables[0] : '('.implode(', ', $tables).')'; - } - - // -------------------------------------------------------------------- - /** * Get UPDATE query string * @@ -2058,7 +2040,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // Write the "FROM" portion of the query if (count($this->qb_from) > 0) { - $sql .= "\nFROM ".$this->_from_tables($this->qb_from); + $sql .= "\nFROM ".implode(', ', $this->qb_from); } // Write the "JOIN" portion of the query diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index f7811bf46..ab1d1b88d 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -301,22 +301,6 @@ class CI_DB_ibase_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * From Tables - * - * This public function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index b4a1af7ba..a62ea94b3 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -361,22 +361,6 @@ class CI_DB_mssql_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 7bf18949b..72cbce5c1 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -542,22 +542,6 @@ class CI_DB_oci8_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Insert_batch statement * diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index fbf6a4cb1..c1f6ccfe2 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -288,22 +288,6 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Truncate statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php index e287f5c63..efc0500a5 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php @@ -129,22 +129,6 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 7060c9eb9..2346e683e 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -152,22 +152,6 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php index c074a9a78..6fba764a9 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php @@ -138,22 +138,6 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php index 832c03c96..399182e12 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php @@ -164,22 +164,6 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php index a3efc63dc..028121540 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php @@ -158,22 +158,6 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php index 56ec1bce1..d584d1f5b 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -145,22 +145,6 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Insert_batch statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php index dd7a1af52..e7ab3fd50 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -155,22 +155,6 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index 9a476f143..2a687812a 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -141,22 +141,6 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index f125b8f50..ee7c1d15a 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -181,22 +181,6 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 1d6e9567a..2a91a8959 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -456,22 +456,6 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index abcaf4577..a6739d192 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -357,22 +357,6 @@ class CI_DB_sqlsrv_driver extends CI_DB { // -------------------------------------------------------------------- - /** - * From Tables - * - * This function implicitly groups FROM tables so there is no confusion - * about operator precedence in harmony with SQL standards - * - * @param array - * @return string - */ - protected function _from_tables($tables) - { - return is_array($tables) ? implode(', ', $tables) : $tables; - } - - // -------------------------------------------------------------------- - /** * Update statement * diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 87b01743e..47429aed3 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -358,6 +358,7 @@ Bug fixes for 3.0 - Fixed a bug (#1692) - :doc:`Database Library ` method ``display_error()`` didn't properly trace the possible error source on Windows systems. - Fixed a bug (#1745) - ``is_write_type()`` method in the :doc:`Database Library ` didn't return TRUE for LOAD queries. - Fixed a bug (#1765) - :doc:`Database Library ` didn't properly detect connection errors for MySQLi. +- Fixed a bug (#1257) - :doc:`Query Builder ` used to (unnecessarily) group FROM clause contents, which breaks certain queries and is invalid for some databases. Version 2.1.2 ============= -- cgit v1.2.3-24-g4f1b From 960e616d18c77f463e7c53f666d98b09f5ca9057 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sun, 7 Oct 2012 15:48:55 +0300 Subject: Fix a typo [ci skip] --- user_guide_src/source/libraries/form_validation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/libraries/form_validation.rst b/user_guide_src/source/libraries/form_validation.rst index 14305b664..22272dc9b 100644 --- a/user_guide_src/source/libraries/form_validation.rst +++ b/user_guide_src/source/libraries/form_validation.rst @@ -399,7 +399,7 @@ The validation system supports callbacks to your own validation functions. This permits you to extend the validation class to meet your needs. For example, if you need to run a database query to see if the user is choosing a unique username, you can create a callback function -that does that. Let's create a example of this. +that does that. Let's create an example of this. In your controller, change the "username" rule to this:: -- cgit v1.2.3-24-g4f1b