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 (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 1 deletion(-) (limited to 'system') 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 */ -- 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'system') 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) { -- cgit v1.2.3-24-g4f1b From 824085200b3362bfe1db1ecce52bf555dd064b57 Mon Sep 17 00:00:00 2001 From: rwillert Date: Tue, 10 Jul 2012 14:02:01 +0300 Subject: Reconnect to PostgreSQL database if connection droped. --- system/database/drivers/postgre/postgre_driver.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 20b78673e..c24c523de 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -132,7 +132,15 @@ class CI_DB_postgre_driver extends CI_DB { */ public function db_pconnect() { - return @pg_pconnect($this->dsn); + $conn = @pg_pconnect($this->dsn); + if ($conn && pg_connection_status($conn) === PGSQL_CONNECTION_BAD) + { + if (pg_ping($conn) === FALSE) + { + return FALSE; + } + } + return $conn; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 6e7047576338e896a43a35eb2fa79136adc01d8d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 18 Jul 2012 00:46:33 +0300 Subject: Fix WHERE escaping/prefixing --- system/database/DB_driver.php | 17 ++++- system/database/DB_query_builder.php | 121 ++++++++++++++++++++++++----------- 2 files changed, 100 insertions(+), 38 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index d63a1d955..b7c6b4e8e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1168,8 +1168,21 @@ abstract class CI_DB_driver { */ protected function _get_operator($str) { - return preg_match('/(=|!|<|>| IS NULL| IS NOT NULL| BETWEEN)/i', $str, $match) - ? $match[1] : FALSE; + static $_operators = array( + '\s*(?:<|>|!)?=\s*', // =, <=, >=, != + '\s*<>?\s*', // <, <> + '\s*>\s*', // > + '\s+IS NULL', // IS NULL + '\s+IS NOT NULL', // IS NOT NULL + '\s+LIKE\s+', // LIKE + '\s+NOT LIKE\s+', // NOT LIKE + '\s+BETWEEN\s+\S+\s+AND\s+\S+', // BETWEEN value AND value + '\s+IN\s*\([^\)]+\)', // IN(list) + '\s+NOT IN\s*\([^\)]+\)' // NOT IN (list) + ); + + return preg_match('/'.implode('|', $_operators).'/i', $str, $match) + ? $match[0] : FALSE; } // -------------------------------------------------------------------- diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 479b7f24a..92cb8c1d5 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -467,13 +467,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { ? $this->_group_get_type('') : $this->_group_get_type($type); - if ($escape === TRUE) - { - $k = (($op = $this->_get_operator($k)) !== FALSE) - ? $this->escape_identifiers(trim(substr($k, 0, strpos($k, $op)))).' '.strstr($k, $op) - : $this->escape_identifiers(trim($k)); - } - if (is_null($v) && ! $this->_has_operator($k)) { // value appears not to have been set, assign the test to IS NULL @@ -493,10 +486,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } } - $this->qb_where[] = $prefix.$k.$v; + $this->qb_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); if ($this->qb_caching === TRUE) { - $this->qb_cache_where[] = $prefix.$k.$v; + // check this shit + $this->qb_cache_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); $this->qb_cache_exists[] = 'where'; } @@ -607,14 +601,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_wherein[] = $this->escape($value); } - if ($escape === TRUE) - { - $key = $this->escape_identifiers(trim($key)); - } - $prefix = (count($this->qb_where) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); - $this->qb_where[] = $where_in = $prefix.$key.$not.' IN ('.implode(', ', $this->qb_wherein).') '; + $where_in = array( + 'condition' => $prefix.$key.$not.' IN('.implode(', ', $this->qb_wherein).')', + 'escape' => $escape + ); + $this->qb_where[] = $where_in; if ($this->qb_caching === TRUE) { $this->qb_cache_where[] = $where_in; @@ -769,11 +762,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_where_group_started = TRUE; $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) ? '' : $type; - $this->qb_where[] = $value = $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' ('; + $where = array( + 'condition' => $prefix.$not.str_repeat(' ', ++$this->qb_where_group_count).' (', + 'escape' => FALSE + ); + $this->qb_where[] = $where; if ($this->qb_caching) { - $this->qb_cache_where[] = $value; + $this->qb_cache_where[] = $where; } return $this; @@ -825,11 +822,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver { public function group_end() { $this->qb_where_group_started = FALSE; - $this->qb_where[] = $value = str_repeat(' ', $this->qb_where_group_count--) . ')'; + $where = array( + 'condition' => str_repeat(' ', $this->qb_where_group_count--).')', + 'escape' => FALSE + ); + $this->qb_where[] = $where; if ($this->qb_caching) { - $this->qb_cache_where[] = $value; + $this->qb_cache_where[] = $where; } return $this; @@ -2067,49 +2068,97 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql .= "\n".implode("\n", $this->qb_join); } - // Write the "WHERE" portion of the query - if (count($this->qb_where) > 0 OR count($this->qb_like) > 0) + $sql .= $this->_compile_conditions(); + + // Write the "LIMIT" portion of the query + if (is_numeric($this->qb_limit)) { - $sql .= "\nWHERE "; + return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset); } - $sql .= implode("\n", $this->qb_where); + return $sql; + } - // Write the "LIKE" portion of the query - if (count($this->qb_like) > 0) + // -------------------------------------------------------------------- + + /** + * Compile WHERE statement + * + * Escapes identifiers in WHERE, LIKE, HAVING, GROUP BY, ORDER BY + * statements at execution time. Required so that aliases are tracked + * properly, regardless of wether e.g. where() is called prior to + * join() and dbprefix is added only if needed. + * + * @return string + */ + protected function _compile_conditions() + { + // WHERE + if (count($this->qb_where) > 0) { - if (count($this->qb_where) > 0) + $sql = "\nWHERE "; + + for ($i = 0, $c = count($this->qb_where); $i < $c; $i++) { - $sql .= "\nAND "; + if ($this->qb_where[$i]['escape'] === FALSE) + { + $this->qb_where[$i] = $this->qb_where[$i]['condition']; + continue; + } + + $op = preg_quote($this->_get_operator($this->qb_where[$i]['condition'])); + if ( ! preg_match('/^(\s*(?:AND|OR)\s+)?(\(?)(.*)('.$op.')(.*(?qb_where[$i]['condition'], $matches)) + { + $this->qb_where[$i] = $this->qb_where[$i]['condition']; + continue; + } + + // $matches = array( + // 0 => 'OR (test <= foo)', /* the whole thing */ + // 1 => 'OR ', /* optional */ + // 2 => '(', /* optional */ + // 3 => 'test', /* the field name */ + // 4 => ' <= ', /* $op */ + // 5 => 'foo', /* optional, if $op is e.g. 'IS NULL' */ + // 6 => ')' /* optional */ + // ); + empty($matches[5]) OR $matches[5] = ' '.$this->protect_identifiers(trim($matches[5])); + $this->qb_where[$i] = $matches[1].$matches[2].$this->protect_identifiers(trim($matches[3])) + .' '.trim($matches[4]).$matches[5].$matches[6]; } + $sql .= implode("\n", $this->qb_where); + } + else + { + $sql = ''; + } + + // LIKE + if (count($this->qb_like) > 0) + { + $sql .= ($sql === '') ? "\nWHERE " : "\nAND "; $sql .= implode("\n", $this->qb_like); } - // Write the "GROUP BY" portion of the query + // GROUP BY if (count($this->qb_groupby) > 0) { $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby); } - // Write the "HAVING" portion of the query + // HAVING if (count($this->qb_having) > 0) { $sql .= "\nHAVING ".implode("\n", $this->qb_having); } - // Write the "ORDER BY" portion of the query + // ORDER BY if (count($this->qb_orderby) > 0) { $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby); } - // Write the "LIMIT" portion of the query - if (is_numeric($this->qb_limit)) - { - return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset); - } - return $sql; } -- cgit v1.2.3-24-g4f1b From ededc4a32a96315f18b7234153aa9cf7c87ca3ce Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 18 Jul 2012 01:16:15 +0300 Subject: Change _like() to append to the qb_where array --- system/database/DB_query_builder.php | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 92cb8c1d5..75da1c792 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -692,7 +692,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Like * - * Called by like() or orlike() + * Called by like() or or_like() * * @param mixed * @param mixed @@ -708,8 +708,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { foreach ($field as $k => $v) { - $k = $this->protect_identifiers($k); - $prefix = (count($this->qb_like) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + ? $this->_group_get_type('') : $this->_group_get_type($type); $v = $this->escape_like_str($v); if ($side === 'none') @@ -735,13 +735,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); } - $this->qb_like[] = $like_statement; + $this->qb_where[] = array('condition' => $like_statement, 'escape' => $this->_protect_identifiers); if ($this->qb_caching === TRUE) { - $this->qb_cache_like[] = $like_statement; - $this->qb_cache_exists[] = 'like'; + $this->qb_cache_where[] = $like_statement; + $this->qb_cache_exists[] = 'where'; } - } return $this; @@ -2134,13 +2133,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql = ''; } - // LIKE - if (count($this->qb_like) > 0) - { - $sql .= ($sql === '') ? "\nWHERE " : "\nAND "; - $sql .= implode("\n", $this->qb_like); - } - // GROUP BY if (count($this->qb_groupby) > 0) { -- cgit v1.2.3-24-g4f1b From b04786599e1b032078f1d3bdd8941405d47447a0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 18 Jul 2012 15:34:46 +0300 Subject: Remove dependancies on qb_like and remove unneeded parameters from _delete(), _like(), _update(), _update_batch() --- system/database/DB_driver.php | 53 ++++---- system/database/DB_query_builder.php | 147 ++++++++++----------- system/database/drivers/cubrid/cubrid_driver.php | 10 +- system/database/drivers/ibase/ibase_driver.php | 36 +---- system/database/drivers/mssql/mssql_driver.php | 41 ++---- system/database/drivers/mysql/mysql_driver.php | 10 +- system/database/drivers/mysqli/mysqli_driver.php | 10 +- system/database/drivers/oci8/oci8_driver.php | 17 +-- system/database/drivers/odbc/odbc_driver.php | 34 +++++ system/database/drivers/pdo/pdo_driver.php | 13 +- .../drivers/pdo/subdrivers/pdo_4d_driver.php | 37 +----- .../drivers/pdo/subdrivers/pdo_cubrid_driver.php | 10 +- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 41 ++---- .../drivers/pdo/subdrivers/pdo_firebird_driver.php | 36 +---- .../drivers/pdo/subdrivers/pdo_ibm_driver.php | 37 +----- .../drivers/pdo/subdrivers/pdo_informix_driver.php | 37 +----- .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 10 +- .../drivers/pdo/subdrivers/pdo_oci_driver.php | 17 +-- .../drivers/pdo/subdrivers/pdo_odbc_driver.php | 37 +----- .../drivers/pdo/subdrivers/pdo_pgsql_driver.php | 67 +++------- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 41 ++---- system/database/drivers/postgre/postgre_driver.php | 69 +++------- system/database/drivers/sqlsrv/sqlsrv_driver.php | 41 ++---- 23 files changed, 297 insertions(+), 554 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b7c6b4e8e..10306d721 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1118,31 +1118,19 @@ abstract class CI_DB_driver { * Generates a platform-specific update string from the supplied data * * @param string the table name - * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { foreach ($values as $key => $val) { $valstr[] = $key.' = '.$val; } - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .$where - .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : '') - .($limit ? ' LIMIT '.$limit : ''); + .$this->_compile_where() + .(empty($this->qb_orderby) ? '' : ' ORDER BY '.implode(', ', $this->qb_orderby)) + .($this->qb_limit ? ' LIMIT '.(int) $this->qb_limit : ''); } // -------------------------------------------------------------------- @@ -1155,7 +1143,7 @@ abstract class CI_DB_driver { */ protected function _has_operator($str) { - return (bool) preg_match('/(\s|<|>|!|=|IS NULL|IS NOT NULL|BETWEEN)/i', trim($str)); + return (bool) preg_match('/(<|>|!|=|\sIS NULL|\sIS NOT NULL|\sBETWEEN|\sLIKE|\sIN\s*\(|\s)/i', trim($str)); } // -------------------------------------------------------------------- @@ -1169,18 +1157,29 @@ abstract class CI_DB_driver { protected function _get_operator($str) { static $_operators = array( - '\s*(?:<|>|!)?=\s*', // =, <=, >=, != - '\s*<>?\s*', // <, <> - '\s*>\s*', // > - '\s+IS NULL', // IS NULL - '\s+IS NOT NULL', // IS NOT NULL - '\s+LIKE\s+', // LIKE - '\s+NOT LIKE\s+', // NOT LIKE - '\s+BETWEEN\s+\S+\s+AND\s+\S+', // BETWEEN value AND value - '\s+IN\s*\([^\)]+\)', // IN(list) - '\s+NOT IN\s*\([^\)]+\)' // NOT IN (list) + '\s*(?:<|>|!)?=\s*', // =, <=, >=, != + '\s*<>?\s*', // <, <> + '\s*>\s*', // > + '\s+IS NULL', // IS NULL + '\s+IS NOT NULL', // IS NOT NULL + '\s+BETWEEN\s+\S+\s+AND\s+\S+', // BETWEEN value AND value + '\s+IN\s*\([^\)]+\)', // IN(list) + '\s+NOT IN\s*\([^\)]+\)' // NOT IN (list) + ); + + static $_like = array( + '\s+LIKE\s+\S+', // LIKE 'expr' + '\s+NOT LIKE\s+\S+', // NOT LIKE 'expr' ); + if ($this->_like_escape_str !== '') + { + $_like[0] .= preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))); + $_like[1] .= preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))); + } + + $_operators = array_merge($_operators, $_like); + return preg_match('/'.implode('|', $_operators).'/i', $str, $match) ? $match[0] : FALSE; } diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 75da1c792..29b75cd1d 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -47,7 +47,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { protected $qb_from = array(); protected $qb_join = array(); protected $qb_where = array(); - protected $qb_like = array(); protected $qb_groupby = array(); protected $qb_having = array(); protected $qb_keys = array(); @@ -443,12 +442,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Where * - * Called by where() or or_where() + * Called by where(), or_where() * * @param mixed * @param mixed * @param string - * @param mixed + * @param bool * @return object */ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) @@ -477,7 +476,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { if ($escape === TRUE) { - $v = ' '.$this->escape($v); + $v = ' '.(is_int($v) ? $v : $this->escape($v)); } if ( ! $this->_has_operator($k)) @@ -628,12 +627,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * multiple calls with AND * * @param mixed - * @param mixed + * @param string + * @param string + * @param bool * @return object */ - public function like($field, $match = '', $side = 'both') + public function like($field, $match = '', $side = 'both', $escape = NULL) { - return $this->_like($field, $match, 'AND ', $side); + return $this->_like($field, $match, 'AND ', $side, '', $escape); } // -------------------------------------------------------------------- @@ -645,12 +646,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * multiple calls with AND * * @param mixed - * @param mixed + * @param string + * @param string + * @param bool * @return object */ - public function not_like($field, $match = '', $side = 'both') + public function not_like($field, $match = '', $side = 'both', $escape = NULL) { - return $this->_like($field, $match, 'AND ', $side, 'NOT'); + return $this->_like($field, $match, 'AND ', $side, 'NOT', $escape); } // -------------------------------------------------------------------- @@ -662,12 +665,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * multiple calls with OR * * @param mixed - * @param mixed + * @param string + * @param string + * @param bool * @return object */ - public function or_like($field, $match = '', $side = 'both') + public function or_like($field, $match = '', $side = 'both', $escape = NULL) { - return $this->_like($field, $match, 'OR ', $side); + return $this->_like($field, $match, 'OR ', $side, '', $escape); } // -------------------------------------------------------------------- @@ -679,12 +684,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * multiple calls with OR * * @param mixed - * @param mixed + * @param string + * @param string + * @param bool * @return object */ - public function or_not_like($field, $match = '', $side = 'both') + public function or_not_like($field, $match = '', $side = 'both', $escape = NULL) { - return $this->_like($field, $match, 'OR ', $side, 'NOT'); + return $this->_like($field, $match, 'OR ', $side, 'NOT', $escape); } // -------------------------------------------------------------------- @@ -692,50 +699,55 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Like * - * Called by like() or or_like() + * Called by like(), or_like(), not_like, or_not_like() * * @param mixed - * @param mixed * @param string + * @param string + * @param string + * @param string + * @param bool * @return object */ - protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') + protected function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '', $escape = NULL) { if ( ! is_array($field)) { $field = array($field => $match); } + is_bool($escape) OR $escape = $this->_protect_identifiers; + $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + ? $this->_group_get_type('') : $this->_group_get_type($type); + foreach ($field as $k => $v) { - $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) - ? $this->_group_get_type('') : $this->_group_get_type($type); $v = $this->escape_like_str($v); if ($side === 'none') { - $like_statement = "{$prefix} $k $not LIKE '{$v}'"; + $like_statement = "{$prefix} {$k} {$not} LIKE '{$v}'"; } elseif ($side === 'before') { - $like_statement = "{$prefix} $k $not LIKE '%{$v}'"; + $like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}'"; } elseif ($side === 'after') { - $like_statement = "{$prefix} $k $not LIKE '{$v}%'"; + $like_statement = "{$prefix} {$k} {$not} LIKE '{$v}%'"; } else { - $like_statement = "{$prefix} $k $not LIKE '%{$v}%'"; + $like_statement = "{$prefix} {$k} {$not} LIKE '%{$v}%'"; } // some platforms require an escape sequence definition for LIKE wildcards if ($this->_like_escape_str !== '') { - $like_statement = $like_statement.sprintf($this->_like_escape_str, $this->_like_escape_chr); + $like_statement .= sprintf($this->_like_escape_str, $this->_like_escape_chr); } - $this->qb_where[] = array('condition' => $like_statement, 'escape' => $this->_protect_identifiers); + $this->qb_where[] = array('condition' => $like_statement, 'escape' => $escape); if ($this->qb_caching === TRUE) { $this->qb_cache_where[] = $like_statement; @@ -1558,7 +1570,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { return FALSE; } - $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit); + $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set); if ($reset === TRUE) { @@ -1605,7 +1617,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->limit($limit); } - $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set, $this->qb_where, $this->qb_orderby, $this->qb_limit, $this->qb_like); + $sql = $this->_update($this->protect_identifiers($this->qb_from[0], TRUE, NULL, FALSE), $this->qb_set); $this->_reset_write(); return $this->query($sql); @@ -1687,7 +1699,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // Batch this baby for ($i = 0, $total = count($this->qb_set); $i < $total; $i += 100) { - $this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, 100), $this->protect_identifiers($index), $this->qb_where)); + $this->query($this->_update_batch($this->protect_identifiers($table, TRUE, NULL, FALSE), array_slice($this->qb_set, $i, 100), $this->protect_identifiers($index))); } $this->_reset_write(); @@ -1893,12 +1905,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->limit($limit); } - if (count($this->qb_where) === 0 && count($this->qb_wherein) === 0 && count($this->qb_like) === 0) + if (count($this->qb_where) === 0 && count($this->qb_wherein) === 0) { return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE; } - $sql = $this->_delete($table, $this->qb_where, $this->qb_like, $this->qb_limit); + $sql = $this->_delete($table); if ($reset_data) { $this->_reset_write(); @@ -1915,21 +1927,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - return 'DELETE FROM '.$table - .(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : '') - .($limit ? ' LIMIT '.(int) $limit : ''); + return 'DELETE FROM '.$table.$this->_compile_where() + .($this->qb_limit ? ' LIMIT '.(int) $this->qb_limit : ''); } // -------------------------------------------------------------------- @@ -2069,6 +2072,24 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql .= $this->_compile_conditions(); + // GROUP BY + if (count($this->qb_groupby) > 0) + { + $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby); + } + + // HAVING + if (count($this->qb_having) > 0) + { + $sql .= "\nHAVING ".implode("\n", $this->qb_having); + } + + // ORDER BY + if (count($this->qb_orderby) > 0) + { + $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby); + } + // Write the "LIMIT" portion of the query if (is_numeric($this->qb_limit)) { @@ -2083,14 +2104,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Compile WHERE statement * - * Escapes identifiers in WHERE, LIKE, HAVING, GROUP BY, ORDER BY - * statements at execution time. Required so that aliases are tracked - * properly, regardless of wether e.g. where() is called prior to - * join() and dbprefix is added only if needed. + * Escapes identifiers in WHERE statements at execution time. + * Required so that aliases are tracked properly, regardless of wether + * e.g. where() is called prior to join() and dbprefix is added only + * if needed. * * @return string */ - protected function _compile_conditions() + protected function _compile_where() { // WHERE if (count($this->qb_where) > 0) @@ -2126,32 +2147,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver { .' '.trim($matches[4]).$matches[5].$matches[6]; } - $sql .= implode("\n", $this->qb_where); - } - else - { - $sql = ''; + return implode("\n", $this->qb_where); } - // GROUP BY - if (count($this->qb_groupby) > 0) - { - $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby); - } - - // HAVING - if (count($this->qb_having) > 0) - { - $sql .= "\nHAVING ".implode("\n", $this->qb_having); - } - - // ORDER BY - if (count($this->qb_orderby) > 0) - { - $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby); - } - - return $sql; + return ''; } // -------------------------------------------------------------------- @@ -2363,7 +2362,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { 'qb_from' => array(), 'qb_join' => array(), 'qb_where' => array(), - 'qb_like' => array(), 'qb_groupby' => array(), 'qb_having' => array(), 'qb_orderby' => array(), @@ -2392,7 +2390,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { 'qb_set' => array(), 'qb_from' => array(), 'qb_where' => array(), - 'qb_like' => array(), 'qb_orderby' => array(), 'qb_keys' => array(), 'qb_limit' => FALSE diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index a3d0287f5..e2ace3320 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -396,10 +396,10 @@ class CI_DB_cubrid_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -423,9 +423,9 @@ class CI_DB_cubrid_driver extends CI_DB { .'ELSE '.$k.' END, '; } - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN ('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index c9027670d..86c1fee6d 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -328,29 +328,12 @@ class CI_DB_ibase_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .$where - .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : ''); + $this->qb_limit = FALSE; + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -379,19 +362,12 @@ class CI_DB_ibase_driver extends CI_DB { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 1714704a8..672c3161c 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -388,27 +388,13 @@ class CI_DB_mssql_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).' WHERE '.$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -437,23 +423,16 @@ class CI_DB_mssql_driver extends CI_DB { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + } - return ($limit) - ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete' - : 'DELETE FROM '.$table.$conditions; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 29db90408..634430665 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -420,10 +420,10 @@ class CI_DB_mysql_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -447,9 +447,9 @@ class CI_DB_mysql_driver extends CI_DB { .'ELSE '.$k.' END, '; } - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index be61aab20..5498aa244 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -412,10 +412,10 @@ class CI_DB_mysqli_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -439,11 +439,9 @@ class CI_DB_mysqli_driver extends CI_DB { .'ELSE '.$k.' END, '; } - $where = ($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : ''; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN('.implode(',', $ids).')'; + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 691247fee..a0f26c257 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -611,20 +611,17 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - empty($limit) OR $conditions[] = 'rownum <= '.$limit; + if ($this->qb_limit) + { + $this->where('rownum <= ', (int) $this->qb_limit, FALSE); + $this->qb_limit = FALSE; + } - return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 8f0a474b0..f62400245 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -306,6 +306,24 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Update statement + * + * Generates a platform-specific update string from the supplied data + * + * @param string the table name + * @param array the update data + * @return string + */ + protected function _update($table, $values) + { + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); + } + + // -------------------------------------------------------------------- + /** * Truncate statement * @@ -324,6 +342,22 @@ class CI_DB_odbc_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * Delete statement + * + * Generates a platform-specific delete string from the supplied data + * + * @param string the table name + * @return string + */ + protected function _delete($table) + { + $this->qb_limit = FALSE; + return parent::_delete($table); + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index b36a3d927..a6e2a6264 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -360,14 +360,12 @@ class CI_DB_pdo_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); - $where = ($where !== '' && count($where) >=1) ? implode(" ", $where).' AND ' : ''; - foreach ($values as $key => $val) { $ids[] = $val[$index]; @@ -381,9 +379,7 @@ class CI_DB_pdo_driver extends CI_DB { } } - $sql = 'UPDATE '.$table.' SET '; $cases = ''; - foreach ($final as $k => $v) { $cases .= $k.' = CASE '."\n"; @@ -396,10 +392,9 @@ class CI_DB_pdo_driver extends CI_DB { $cases .= 'ELSE '.$k.' END, '; } - $sql .= substr($cases, 0, -2); - $sql .= ' WHERE '.$where.$index.' IN ('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return $sql; + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php index e287f5c63..014112401 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php @@ -152,27 +152,13 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -183,21 +169,12 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; - - return 'DELETE FROM '.$table.$conditions; + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php index 05eeacfe6..be85c8644 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -133,10 +133,10 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -160,9 +160,9 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver { .'ELSE '.$k.' END), '; } - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 7060c9eb9..6df9cc638 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -175,27 +175,13 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -206,23 +192,16 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + } - return ($limit) - ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete' - : 'DELETE FROM '.$table.$conditions; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php index c074a9a78..ee21ed22f 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php @@ -161,29 +161,12 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .$where - .(count($orderby) > 0 ? ' ORDER BY '.implode(', ', $orderby) : ''); + $this->qb_limit = FALSE; + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -212,19 +195,12 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php index 832c03c96..7563a42d6 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_ibm_driver.php @@ -187,27 +187,13 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -218,21 +204,12 @@ class CI_DB_pdo_ibm_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; - - return 'DELETE FROM '.$table.$conditions; + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php index a3efc63dc..a6869a7d2 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php @@ -181,27 +181,13 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -230,21 +216,12 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; - - return 'DELETE FROM '.$table.$conditions; + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 78afe246c..e10a84545 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -161,10 +161,10 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -188,9 +188,9 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { .'ELSE '.$k.' END), '; } - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php index 56ec1bce1..494d82c3f 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -190,20 +190,17 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - empty($limit) OR $conditions[] = 'rownum <= '.$limit; + if ($this->qb_limit) + { + $this->where('rownum <= ', (int) $this->qb_limit, FALSE); + $this->qb_limit = FALSE; + } - return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php index 392754ff7..722acad89 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -179,27 +179,13 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -228,21 +214,12 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; - - return 'DELETE FROM '.$table.$conditions; + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index 9a476f143..d2afd1d71 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -164,27 +164,13 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -196,10 +182,10 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -218,14 +204,14 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { $cases = ''; foreach ($final as $k => $v) { - $cases .= $k.' = (CASE '.$k."\n" + $cases .= $k.' = (CASE '.$index."\n" .implode("\n", $v)."\n" .'ELSE '.$k.' END), '; } - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- @@ -236,19 +222,12 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- @@ -273,11 +252,12 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { /** * Where * - * Called by where() or or_where() + * Called by where(), or_where() * * @param mixed * @param mixed * @param string + * @param bool * @return object */ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) @@ -296,10 +276,6 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { ? $this->_group_get_type('') : $this->_group_get_type($type); - $k = (($op = $this->_get_operator($k)) !== FALSE) - ? $this->protect_identifiers(substr($k, 0, strpos($k, $op)), FALSE, $escape).strstr($k, $op) - : $this->protect_identifiers($k, FALSE, $escape); - if (is_null($v) && ! $this->_has_operator($k)) { // value appears not to have been set, assign the test to IS NULL @@ -308,13 +284,13 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { if ( ! is_null($v)) { - if ($escape === TRUE) + if (is_bool($v)) { - $v = ' '.$this->escape($v); + $v = ' '.($v ? 'TRUE' : 'FALSE'); } - elseif (is_bool($v)) + elseif ($escape === TRUE) { - $v = ($v ? ' TRUE' : ' FALSE'); + $v = ' '.(is_int($v) ? $v : $this->escape($v)); } if ( ! $this->_has_operator($k)) @@ -323,10 +299,11 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { } } - $this->qb_where[] = $prefix.$k.$v; + $this->qb_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); if ($this->qb_caching === TRUE) { - $this->qb_cache_where[] = $prefix.$k.$v; + // check this shit + $this->qb_cache_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); $this->qb_cache_exists[] = 'where'; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index f125b8f50..1896225f0 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -204,27 +204,13 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -235,23 +221,16 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + } - return ($limit) - ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete' - : 'DELETE FROM '.$table.$conditions; + return parent::_delete($table); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 031740851..15059f3d4 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -475,27 +475,13 @@ class CI_DB_postgre_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -507,10 +493,10 @@ class CI_DB_postgre_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause + * @param string the where key * @return string */ - protected function _update_batch($table, $values, $index, $where = NULL) + protected function _update_batch($table, $values, $index) { $ids = array(); foreach ($values as $key => $val) @@ -534,9 +520,9 @@ class CI_DB_postgre_driver extends CI_DB { .'ELSE '.$k.' END), '; } - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2) - .' WHERE '.(($where !== '' && count($where) > 0) ? implode(' ', $where).' AND ' : '') - .$index.' IN('.implode(',', $ids).')'; + $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); + + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); } // -------------------------------------------------------------------- @@ -547,19 +533,12 @@ class CI_DB_postgre_driver extends CI_DB { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause (ignored) * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - return 'DELETE FROM '.$table.(count($conditions) > 0 ? ' WHERE '.implode(' AND ', $conditions) : ''); + $this->qb_limit = FALSE; + return parent::_delete($table); } // -------------------------------------------------------------------- @@ -584,12 +563,12 @@ class CI_DB_postgre_driver extends CI_DB { /** * Where * - * Called by where() or or_where() + * Called by where(), or_where() * * @param mixed * @param mixed * @param string - * @param mixed + * @param bool * @return object */ protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) @@ -608,13 +587,6 @@ class CI_DB_postgre_driver extends CI_DB { ? $this->_group_get_type('') : $this->_group_get_type($type); - if ($escape === TRUE) - { - $k = (($op = $this->_get_operator($k)) !== FALSE) - ? $this->escape_identifiers(trim(substr($k, 0, strpos($k, $op)))).' '.strstr($k, $op) - : $this->escape_identifiers(trim($k)); - } - if (is_null($v) && ! $this->_has_operator($k)) { // value appears not to have been set, assign the test to IS NULL @@ -623,13 +595,13 @@ class CI_DB_postgre_driver extends CI_DB { if ( ! is_null($v)) { - if ($escape === TRUE) + if (is_bool($v)) { - $v = ' '.$this->escape($v); + $v = ' '.($v ? 'TRUE' : 'FALSE'); } - elseif (is_bool($v)) + elseif ($escape === TRUE) { - $v = ($v ? ' TRUE' : ' FALSE'); + $v = ' '.(is_int($v) ? $v : $this->escape($v)); } if ( ! $this->_has_operator($k)) @@ -638,10 +610,11 @@ class CI_DB_postgre_driver extends CI_DB { } } - $this->qb_where[] = $prefix.$k.$v; + $this->qb_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); if ($this->qb_caching === TRUE) { - $this->qb_cache_where[] = $prefix.$k.$v; + // check this shit + $this->qb_cache_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); $this->qb_cache_exists[] = 'where'; } diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 8bd18bd76..6baa152e8 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -384,27 +384,13 @@ class CI_DB_sqlsrv_driver extends CI_DB { * * @param string the table name * @param array the update data - * @param array the where clause - * @param array the orderby clause (ignored) - * @param array the limit clause (ignored) - * @param array the like clause * @return string */ - protected function _update($table, $values, $where, $orderby = array(), $limit = FALSE, $like = array()) + protected function _update($table, $values) { - foreach ($values as $key => $val) - { - $valstr[] = $key.' = '.$val; - } - - $where = empty($where) ? '' : ' WHERE '.implode(' ', $where); - - if ( ! empty($like)) - { - $where .= ($where === '' ? ' WHERE ' : ' AND ').implode(' ', $like); - } - - return 'UPDATE '.$table.' SET '.implode(', ', $valstr).$where; + $this->qb_limit = FALSE; + $this->qb_orderby = array(); + return parent::_update($table, $values); } // -------------------------------------------------------------------- @@ -433,23 +419,16 @@ class CI_DB_sqlsrv_driver extends CI_DB { * Generates a platform-specific delete string from the supplied data * * @param string the table name - * @param array the where clause - * @param array the like clause - * @param string the limit clause * @return string */ - protected function _delete($table, $where = array(), $like = array(), $limit = FALSE) + protected function _delete($table) { - $conditions = array(); - - empty($where) OR $conditions[] = implode(' ', $where); - empty($like) OR $conditions[] = implode(' ', $like); - - $conditions = (count($conditions) > 0) ? ' WHERE '.implode(' AND ', $conditions) : ''; + if ($this->qb_limit) + { + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + } - return ($limit) - ? 'WITH ci_delete AS (SELECT TOP '.$limit.' * FROM '.$table.$conditions.') DELETE FROM ci_delete' - : 'DELETE FROM '.$table.$conditions; + return parent::_delete($table); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d40459d94f91219f080caabebd627fdc319b0f42 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 18 Jul 2012 16:46:39 +0300 Subject: Merge where() and having() logic - it's structurally identical and only the keyword differs --- system/database/DB_query_builder.php | 124 ++++++--------------- system/database/drivers/cubrid/cubrid_driver.php | 2 +- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/pdo/pdo_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_cubrid_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 2 +- .../drivers/pdo/subdrivers/pdo_pgsql_driver.php | 20 ++-- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 2 +- system/database/drivers/postgre/postgre_driver.php | 20 ++-- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- 13 files changed, 69 insertions(+), 115 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 29b75cd1d..34a77c551 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -416,7 +416,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function where($key, $value = NULL, $escape = NULL) { - return $this->_where($key, $value, 'AND ', $escape); + return $this->_wh('qb_where', $key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- @@ -434,24 +434,27 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function or_where($key, $value = NULL, $escape = NULL) { - return $this->_where($key, $value, 'OR ', $escape); + return $this->_wh('qb_where', $key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- /** - * Where + * WHERE, HAVING * - * Called by where(), or_where() + * Called by where(), or_where(), having(), or_having() * + * @param string 'qb_where' or 'qb_having' * @param mixed * @param mixed * @param string * @param bool * @return object */ - protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL) { + $qb_cache_key = ($qb_key === 'qb_having') ? 'qb_cache_having' : 'qb_cache_where'; + if ( ! is_array($key)) { $key = array($key => $value); @@ -462,7 +465,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { foreach ($key as $k => $v) { - $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + $prefix = (count($this->$qb_key) === 0 && count($this->$qb_cache_key) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); @@ -485,12 +488,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } } - $this->qb_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); + $this->{$qb_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); if ($this->qb_caching === TRUE) { - // check this shit - $this->qb_cache_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); - $this->qb_cache_exists[] = 'where'; + $this->{$qb_cache_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); + $this->qb_cache_exists[] = substr($qb_key, 3); } } @@ -916,7 +918,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function having($key, $value = '', $escape = NULL) { - return $this->_having($key, $value, 'AND ', $escape); + return $this->_wh('qb_having', $key, $value, 'AND ', $escape); } // -------------------------------------------------------------------- @@ -933,58 +935,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function or_having($key, $value = '', $escape = NULL) { - return $this->_having($key, $value, 'OR ', $escape); - } - - // -------------------------------------------------------------------- - - /** - * Sets the HAVING values - * - * Called by having() or or_having() - * - * @param string - * @param string - * @param string - * @param bool - * @return object - */ - protected function _having($key, $value = '', $type = 'AND ', $escape = NULL) - { - if ( ! is_array($key)) - { - $key = array($key => $value); - } - - is_bool($escape) OR $escape = $this->_protect_identifiers; - - foreach ($key as $k => $v) - { - $prefix = (count($this->qb_having) === 0) ? '' : $type; - - $k = $this->_has_operator($k) - ? $this->protect_identifiers(substr($k, 0, strpos(rtrim($k), ' ')), FALSE, $escape).strchr(rtrim($k), ' ') - : $this->protect_identifiers($k, FALSE, $escape); - - if ( ! $this->_has_operator($k)) - { - $k .= ' = '; - } - - if ($v !== '') - { - $v = ' '.$this->escape($v); - } - - $this->qb_having[] = $prefix.$k.$v; - if ($this->qb_caching === TRUE) - { - $this->qb_cache_having[] = $prefix.$k.$v; - $this->qb_cache_exists[] = 'having'; - } - } - - return $this; + return $this->_wh('qb_having', $key, $value, 'OR ', $escape); } // -------------------------------------------------------------------- @@ -1931,7 +1882,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ protected function _delete($table) { - return 'DELETE FROM '.$table.$this->_compile_where() + return 'DELETE FROM '.$table.$this->_compile_wh('qb_where') .($this->qb_limit ? ' LIMIT '.(int) $this->qb_limit : ''); } @@ -2070,7 +2021,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql .= "\n".implode("\n", $this->qb_join); } - $sql .= $this->_compile_conditions(); + // WHERE + $sql .= $this->_compile_wh('qb_where'); // GROUP BY if (count($this->qb_groupby) > 0) @@ -2079,10 +2031,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } // HAVING - if (count($this->qb_having) > 0) - { - $sql .= "\nHAVING ".implode("\n", $this->qb_having); - } + $sql .= $this->_compile_wh('qb_having'); // ORDER BY if (count($this->qb_orderby) > 0) @@ -2090,7 +2039,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby); } - // Write the "LIMIT" portion of the query + // LIMIT if (is_numeric($this->qb_limit)) { return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset); @@ -2102,34 +2051,35 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Compile WHERE statement + * Compile WHERE, HAVING statements + * + * Escapes identifiers in WHERE and HAVING statements at execution time. * - * Escapes identifiers in WHERE statements at execution time. * Required so that aliases are tracked properly, regardless of wether - * e.g. where() is called prior to join() and dbprefix is added only - * if needed. + * where(), or_where(), having(), or_having are called prior to from(), + * join() and dbprefix is added only if needed. * - * @return string + * @param string 'qb_where' or 'qb_having' + * @return string SQL statement */ - protected function _compile_where() + protected function _compile_wh($qb_key) { - // WHERE - if (count($this->qb_where) > 0) + if (count($this->$qb_key) > 0) { - $sql = "\nWHERE "; + $sql = ($qb_key === 'qb_having') ? "\nHAVING " : "\nWHERE "; - for ($i = 0, $c = count($this->qb_where); $i < $c; $i++) + for ($i = 0, $c = count($this->$qb_key); $i < $c; $i++) { - if ($this->qb_where[$i]['escape'] === FALSE) + if ($this->{$qb_key}[$i]['escape'] === FALSE) { - $this->qb_where[$i] = $this->qb_where[$i]['condition']; + $this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition']; continue; } - $op = preg_quote($this->_get_operator($this->qb_where[$i]['condition'])); - if ( ! preg_match('/^(\s*(?:AND|OR)\s+)?(\(?)(.*)('.$op.')(.*(?qb_where[$i]['condition'], $matches)) + $op = preg_quote($this->_get_operator($this->{$qb_key}[$i]['condition'])); + if ( ! preg_match('/^(\s*(?:AND|OR)\s+)?(\(?)(.*)('.$op.')(.*(?{$qb_key}[$i]['condition'], $matches)) { - $this->qb_where[$i] = $this->qb_where[$i]['condition']; + $this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition']; continue; } @@ -2143,11 +2093,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // 6 => ')' /* optional */ // ); empty($matches[5]) OR $matches[5] = ' '.$this->protect_identifiers(trim($matches[5])); - $this->qb_where[$i] = $matches[1].$matches[2].$this->protect_identifiers(trim($matches[3])) + $this->{$qb_key}[$i] = $matches[1].$matches[2].$this->protect_identifiers(trim($matches[3])) .' '.trim($matches[4]).$matches[5].$matches[6]; } - return implode("\n", $this->qb_where); + return implode("\n", $this->$qb_key); } return ''; diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index e2ace3320..e243aae9f 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -425,7 +425,7 @@ class CI_DB_cubrid_driver extends CI_DB { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 672c3161c..35cd85702 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -429,7 +429,7 @@ class CI_DB_mssql_driver extends CI_DB { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 634430665..0a15fe447 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -449,7 +449,7 @@ class CI_DB_mysql_driver extends CI_DB { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 5498aa244..5f5a31d34 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -441,7 +441,7 @@ class CI_DB_mysqli_driver extends CI_DB { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index a6e2a6264..ee5af783e 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -394,7 +394,7 @@ class CI_DB_pdo_driver extends CI_DB { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php index be85c8644..741126310 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -162,7 +162,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 6df9cc638..20d510ff6 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -198,7 +198,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index e10a84545..67da156bf 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -190,7 +190,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index d2afd1d71..510a2a38f 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -211,7 +211,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- @@ -250,18 +250,21 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { // -------------------------------------------------------------------- /** - * Where + * WHERE, HAVING * - * Called by where(), or_where() + * Called by where(), or_where(), having(), or_having() * + * @param string 'qb_where' or 'qb_having' * @param mixed * @param mixed * @param string * @param bool * @return object */ - protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL) { + $qb_cache_key = ($qb_key === 'qb_having') ? 'qb_cache_having' : 'qb_cache_where'; + if ( ! is_array($key)) { $key = array($key => $value); @@ -272,7 +275,7 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { foreach ($key as $k => $v) { - $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + $prefix = (count($this->$qb_key) === 0 && count($this->$qb_cache_key) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); @@ -299,12 +302,11 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { } } - $this->qb_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); + $this->{$qb_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); if ($this->qb_caching === TRUE) { - // check this shit - $this->qb_cache_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); - $this->qb_cache_exists[] = 'where'; + $this->{$qb_cache_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); + $this->qb_cache_exists[] = substr($qb_key, 3); } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 1896225f0..39cb5f9ef 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -227,7 +227,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 15059f3d4..1c03f6831 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -522,7 +522,7 @@ class CI_DB_postgre_driver extends CI_DB { $this->where($index.' IN('.implode(',', $ids).')', NULL, FALSE); - return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_where(); + return 'UPDATE '.$table.' SET '.substr($cases, 0, -2).$this->_compile_wh('qb_where'); } // -------------------------------------------------------------------- @@ -561,18 +561,21 @@ class CI_DB_postgre_driver extends CI_DB { // -------------------------------------------------------------------- /** - * Where + * WHERE, HAVING * - * Called by where(), or_where() + * Called by where(), or_where(), having(), or_having() * + * @param string 'qb_where' or 'qb_having' * @param mixed * @param mixed * @param string * @param bool * @return object */ - protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) + protected function _wh($qb_key, $key, $value = NULL, $type = 'AND ', $escape = NULL) { + $qb_cache_key = ($qb_key === 'qb_having') ? 'qb_cache_having' : 'qb_cache_where'; + if ( ! is_array($key)) { $key = array($key => $value); @@ -583,7 +586,7 @@ class CI_DB_postgre_driver extends CI_DB { foreach ($key as $k => $v) { - $prefix = (count($this->qb_where) === 0 && count($this->qb_cache_where) === 0) + $prefix = (count($this->$qb_key) === 0 && count($this->$qb_cache_key) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); @@ -610,12 +613,11 @@ class CI_DB_postgre_driver extends CI_DB { } } - $this->qb_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); + $this->{$qb_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); if ($this->qb_caching === TRUE) { - // check this shit - $this->qb_cache_where[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); - $this->qb_cache_exists[] = 'where'; + $this->{$qb_cache_key}[] = array('condition' => $prefix.$k.$v, 'escape' => $escape); + $this->qb_cache_exists[] = substr($qb_key, 3); } } diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 6baa152e8..9ea6facb3 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -425,7 +425,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_where().') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); -- cgit v1.2.3-24-g4f1b From 94611df88cf99ae530258a25e2051e901b9ffcc7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 12:29:54 +0300 Subject: Remove qb_wherein property --- system/database/DB_query_builder.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 34a77c551..7b0565df9 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -54,7 +54,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { protected $qb_offset = FALSE; protected $qb_orderby = array(); protected $qb_set = array(); - protected $qb_wherein = array(); protected $qb_aliased_tables = array(); protected $qb_store_array = array(); protected $qb_where_group_started = FALSE; @@ -597,14 +596,15 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $not = ($not) ? ' NOT' : ''; + $where_in = array(); foreach ($values as $value) { - $this->qb_wherein[] = $this->escape($value); + $wherein[] = $this->escape($value); } $prefix = (count($this->qb_where) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); $where_in = array( - 'condition' => $prefix.$key.$not.' IN('.implode(', ', $this->qb_wherein).')', + 'condition' => $prefix.$key.$not.' IN('.implode(', ', $where_in).')', 'escape' => $escape ); @@ -615,8 +615,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_cache_exists[] = 'where'; } - // reset the array for multiple calls - $this->qb_wherein = array(); return $this; } @@ -1856,7 +1854,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->limit($limit); } - if (count($this->qb_where) === 0 && count($this->qb_wherein) === 0) + if (count($this->qb_where) === 0) { return ($this->db_debug) ? $this->display_error('db_del_must_use_where') : FALSE; } @@ -2315,7 +2313,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { 'qb_groupby' => array(), 'qb_having' => array(), 'qb_orderby' => array(), - 'qb_wherein' => array(), 'qb_aliased_tables' => array(), 'qb_no_escape' => array(), 'qb_distinct' => FALSE, -- cgit v1.2.3-24-g4f1b From c9b924c1498847d8f324d81c8994fff0b95f26dc Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 13:06:02 +0300 Subject: Remove _limit()'s extra parameters and qb_limit, qb_offset unneeded typecasts + add _compile_group_by() method --- system/database/DB_driver.php | 2 +- system/database/DB_query_builder.php | 49 ++++++++++++++++------ system/database/drivers/ibase/ibase_driver.php | 15 +++---- system/database/drivers/mssql/mssql_driver.php | 20 +++------ system/database/drivers/oci8/oci8_driver.php | 10 ++--- .../drivers/pdo/subdrivers/pdo_4d_driver.php | 6 +-- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 16 ++++--- .../drivers/pdo/subdrivers/pdo_firebird_driver.php | 10 ++--- .../drivers/pdo/subdrivers/pdo_informix_driver.php | 6 +-- .../drivers/pdo/subdrivers/pdo_oci_driver.php | 10 ++--- .../drivers/pdo/subdrivers/pdo_odbc_driver.php | 6 +-- .../drivers/pdo/subdrivers/pdo_pgsql_driver.php | 6 +-- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 18 ++++---- system/database/drivers/postgre/postgre_driver.php | 6 +-- system/database/drivers/sqlsrv/sqlsrv_driver.php | 16 ++++--- 15 files changed, 95 insertions(+), 101 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 10306d721..43ea10023 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1130,7 +1130,7 @@ abstract class CI_DB_driver { return 'UPDATE '.$table.' SET '.implode(', ', $valstr) .$this->_compile_where() .(empty($this->qb_orderby) ? '' : ' ORDER BY '.implode(', ', $this->qb_orderby)) - .($this->qb_limit ? ' LIMIT '.(int) $this->qb_limit : ''); + .($this->qb_limit ? ' LIMIT '.$this->qb_limit : ''); } // -------------------------------------------------------------------- diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 7b0565df9..55b97bb3f 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -874,15 +874,18 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * GROUP BY * * @param string + * @param bool * @return object */ - public function group_by($by) + public function group_by($by, $escape = NULL) { if (is_string($by)) { $by = explode(',', $by); } + is_bool($escape) OR $escape = $this->_protect_identifiers; + foreach ($by as $val) { $val = trim($val); @@ -1005,7 +1008,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * @param int the offset value * @return object */ - public function limit($value, $offset = NULL) + public function limit($value, $offset = FALSE) { is_null($value) OR $this->qb_limit = (int) $value; empty($offset) OR $this->qb_offset = (int) $offset; @@ -1035,13 +1038,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - return $sql.' LIMIT '.($offset ? $offset.', ' : '').$limit; + return $sql.' LIMIT '.($this->qb_offset ? $this->qb_offset.', ' : '').$this->qb_limit; } // -------------------------------------------------------------------- @@ -1881,7 +1882,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { protected function _delete($table) { return 'DELETE FROM '.$table.$this->_compile_wh('qb_where') - .($this->qb_limit ? ' LIMIT '.(int) $this->qb_limit : ''); + .($this->qb_limit ? ' LIMIT '.$this->qb_limit : ''); } // -------------------------------------------------------------------- @@ -2023,10 +2024,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql .= $this->_compile_wh('qb_where'); // GROUP BY - if (count($this->qb_groupby) > 0) - { - $sql .= "\nGROUP BY ".implode(', ', $this->qb_groupby); - } + $sql .= $this->_compile_group_by(); // HAVING $sql .= $this->_compile_wh('qb_having'); @@ -2038,9 +2036,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver { } // LIMIT - if (is_numeric($this->qb_limit)) + if ($this->qb_limit) { - return $this->_limit($sql."\n", $this->qb_limit, $this->qb_offset); + return $this->_limit($sql."\n"); } return $sql; @@ -2103,6 +2101,31 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Compile GROUP BY + * + * Escapes identifiers in GROUP BY statements at execution time. + * + * Required so that aliases are tracked properly, regardless of wether + * group_by() is called prior to from(), join() and dbprefix is added + * only if needed. + * + * @return string SQL statement + */ + protected function _compile_group_by() + { + if (count($this->qb_groupby) > 0) + { + $sql = "\nGROUP BY "; + + $sql .= implode(', ', $this->qb_groupby); + } + + return ''; + } + + // -------------------------------------------------------------------- + /** * Object to Array * diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index 86c1fee6d..7b37b9999 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -285,7 +285,10 @@ class CI_DB_ibase_driver extends CI_DB { */ protected function _field_data($table) { - return $this->_limit('SELECT * FROM '.$this->protect_identifiers($table), 1, NULL); + $this->qb_limit = 1; + $sql = $this->_limit('SELECT * FROM '.$this->protect_identifiers($table)); + $this->qb_limit = 0; + return $sql; } // -------------------------------------------------------------------- @@ -378,22 +381,20 @@ class CI_DB_ibase_driver extends CI_DB { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { // Limit clause depends on if Interbase or Firebird if (stripos($this->version(), 'firebird') !== FALSE) { - $select = 'FIRST '. (int) $limit - .($offset ? ' SKIP '. (int) $offset : ''); + $select = 'FIRST '.$this->qb_limit + .($this->qb_offset ? ' SKIP '.$this->qb_offset : ''); } else { $select = 'ROWS ' - .($offset ? (int) $offset.' TO '.($limit + $offset) : (int) $limit); + .($this->qb_offset ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); } return preg_replace('`SELECT`i', 'SELECT '.$select, $sql); diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 35cd85702..bfc82a6c2 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -429,7 +429,7 @@ class CI_DB_mssql_driver extends CI_DB { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); @@ -443,25 +443,17 @@ class CI_DB_mssql_driver extends CI_DB { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - // As of SQL Server 2012 (11.0.*) OFFSET is supported - if (version_compare($this->version(), '11', '>=')) - { - return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY'; - } - - $limit = $offset + $limit; + $limit = $this->qb_offset + $this->qb_limit; // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported, // however an ORDER BY clause is required for it to work - if (version_compare($this->version(), '9', '>=') && $offset && ! empty($this->qb_orderby)) + if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); + $orderby = trim($this->_compile_order_by()); // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); @@ -469,7 +461,7 @@ class CI_DB_mssql_driver extends CI_DB { return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') - ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit; + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index a0f26c257..dcc46527c 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -617,7 +617,7 @@ class CI_DB_oci8_driver extends CI_DB { { if ($this->qb_limit) { - $this->where('rownum <= ', (int) $this->qb_limit, FALSE); + $this->where('rownum <= ',$this->qb_limit, FALSE); $this->qb_limit = FALSE; } @@ -632,15 +632,13 @@ class CI_DB_oci8_driver extends CI_DB { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { $this->limit_used = TRUE; - return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit + 1).')' - .($offset ? ' WHERE rnum >= '.($offset + 1): ''); + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' + .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): ''); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php index 014112401..0e6877c28 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_4d_driver.php @@ -185,13 +185,11 @@ class CI_DB_pdo_4d_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - return $sql.' LIMIT '.$limit.($offset ? ' OFFSET '.$offset : ''); + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 20d510ff6..ad699ce23 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -198,7 +198,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); @@ -212,19 +212,17 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - $limit = $offset + $limit; + $limit = $this->qb_offset + $this->qb_limit; // As of SQL Server 2005 (9.0.*) ROW_NUMBER() is supported, // however an ORDER BY clause is required for it to work - if (version_compare($this->version(), '9', '>=') && $offset && ! empty($this->qb_orderby)) + if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); + $orderby = trim($this->_compile_order_by()); // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); @@ -232,7 +230,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') - ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit; + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); @@ -241,4 +239,4 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { } /* End of file pdo_dblib_driver.php */ -/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php */ +/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php index ee21ed22f..5b36342d2 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_firebird_driver.php @@ -211,22 +211,20 @@ class CI_DB_pdo_firebird_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { // Limit clause depends on if Interbase or Firebird if (stripos($this->version(), 'firebird') !== FALSE) { - $select = 'FIRST '. (int) $limit - .($offset > 0 ? ' SKIP '. (int) $offset : ''); + $select = 'FIRST '.$this->qb_limit + .($this->qb_offset > 0 ? ' SKIP '.$this->qb_offset : ''); } else { $select = 'ROWS ' - .($offset > 0 ? (int) $offset.' TO '.($limit + $offset) : (int) $limit); + .($this->qb_offset > 0 ? $this->qb_offset.' TO '.($this->qb_limit + $this->qb_offset) : $this->qb_limit); } return preg_replace('`SELECT`i', 'SELECT '.$select, $sql); diff --git a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php index a6869a7d2..82480498a 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_informix_driver.php @@ -232,13 +232,11 @@ class CI_DB_pdo_informix_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - $select = 'SELECT '.($offset ? 'SKIP '.$offset : '').'FIRST '.$limit.' '; + $select = 'SELECT '.($this->qb_offset ? 'SKIP '.$this->qb_offset : '').'FIRST '.$this->qb_limit.' '; return preg_replace('/^(SELECT\s)/i', $select, $sql, 1); } diff --git a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php index 494d82c3f..cfbb639a8 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_oci_driver.php @@ -196,7 +196,7 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver { { if ($this->qb_limit) { - $this->where('rownum <= ', (int) $this->qb_limit, FALSE); + $this->where('rownum <= ',$this->qb_limit, FALSE); $this->qb_limit = FALSE; } @@ -211,14 +211,12 @@ class CI_DB_pdo_oci_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($offset + $limit + 1).')' - .($offset ? ' WHERE rnum >= '.($offset + 1): ''); + return 'SELECT * FROM (SELECT inner_query.*, rownum rnum FROM ('.$sql.') inner_query WHERE rownum < '.($this->qb_offset + $this->qb_limit + 1).')' + .($this->qb_offset ? ' WHERE rnum >= '.($this->qb_offset + 1): ''); } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php index 722acad89..0c3467484 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_odbc_driver.php @@ -230,13 +230,11 @@ class CI_DB_pdo_odbc_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); + return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$this->qb_limit.' ', $sql); } } diff --git a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php index 510a2a38f..07cf8f56b 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_pgsql_driver.php @@ -238,13 +238,11 @@ class CI_DB_pdo_pgsql_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - return $sql.' LIMIT '.$limit.($offset ? ' OFFSET '.$offset : ''); + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 39cb5f9ef..399d134af 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -227,7 +227,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); @@ -241,24 +241,22 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { // As of SQL Server 2012 (11.0.*) OFFSET is supported if (version_compare($this->version(), '11', '>=')) { - return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY'; + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; } - $limit = $offset + $limit; + $limit = $this->qb_offset + $this->qb_limit; // An ORDER BY clause is required for ROW_NUMBER() to work - if ($offset && ! empty($this->qb_orderby)) + if ($this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); + $orderby = trim($this->_compile_order_by()); // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); @@ -266,7 +264,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') - ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit; + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); @@ -275,4 +273,4 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { } /* End of file pdo_sqlsrv_driver.php */ -/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php */ +/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 1c03f6831..ddcf3f7c3 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -549,13 +549,11 @@ class CI_DB_postgre_driver extends CI_DB { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { - return $sql.' LIMIT '.$limit.($offset ? ' OFFSET '.$offset : ''); + return $sql.' LIMIT '.$this->qb_limit.($this->qb_offset ? ' OFFSET '.$this->qb_offset : ''); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 9ea6facb3..4eb12f910 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -425,7 +425,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { { if ($this->qb_limit) { - return 'WITH ci_delete AS (SELECT TOP '.(int) $this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; + return 'WITH ci_delete AS (SELECT TOP '.$this->qb_limit.' * FROM '.$table.$this->_compile_wh('qb_where').') DELETE FROM ci_delete'; } return parent::_delete($table); @@ -439,24 +439,22 @@ class CI_DB_sqlsrv_driver extends CI_DB { * Generates a platform-specific LIMIT clause * * @param string the sql query string - * @param int the number of rows to limit the query to - * @param int the offset value * @return string */ - protected function _limit($sql, $limit, $offset) + protected function _limit($sql) { // As of SQL Server 2012 (11.0.*) OFFSET is supported if (version_compare($this->version(), '11', '>=')) { - return $sql.' OFFSET '.(int) $offset.' ROWS FETCH NEXT '.(int) $limit.' ROWS ONLY'; + return $sql.' OFFSET '.(int) $this->qb_offset.' ROWS FETCH NEXT '.$this->qb_limit.' ROWS ONLY'; } - $limit = $offset + $limit; + $limit = $this->qb_offset + $this->qb_limit; // An ORDER BY clause is required for ROW_NUMBER() to work - if ($offset && ! empty($this->qb_orderby)) + if ($this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); + $orderby = trim($this->_compile_order_by()); // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); @@ -464,7 +462,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') - ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.((int) $offset + 1).' AND '.$limit; + ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } return preg_replace('/(^\SELECT (DISTINCT)?)/i','\\1 TOP '.$limit.' ', $sql); -- cgit v1.2.3-24-g4f1b From 96feb586c7fc2c232675590fe4e1032198a39535 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 13:12:34 +0300 Subject: Implement group_by() compiler and no_escape feature --- system/database/DB_query_builder.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 55b97bb3f..6c247f957 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -879,21 +879,24 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ public function group_by($by, $escape = NULL) { + is_bool($escape) OR $escape = $this->_protect_identifiers; + if (is_string($by)) { - $by = explode(',', $by); + $by = ($escape === TRUE) + ? explode(',', $by) + : array($by); } - is_bool($escape) OR $escape = $this->_protect_identifiers; - foreach ($by as $val) { $val = trim($val); if ($val !== '') { - $this->qb_groupby[] = $val = $this->protect_identifiers($val); + $val = array('field' => $val, 'escape' => $escape); + $this->qb_groupby[] = $val; if ($this->qb_caching === TRUE) { $this->qb_cache_groupby[] = $val; @@ -2118,6 +2121,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { $sql = "\nGROUP BY "; + for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) + { + $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE) + ? $this->qb_groupby[$i]['field'] + : $this->protect_identifiers($qb_groupby[$i]['field']); + } + $sql .= implode(', ', $this->qb_groupby); } -- cgit v1.2.3-24-g4f1b From 2d486231c0fbc9a5c9ad5bf6897e7bb1aff275ba Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 14:46:51 +0300 Subject: Implement _compile_order_by() --- system/database/DB_driver.php | 4 +- system/database/DB_query_builder.php | 107 ++++++++++++--------- system/database/drivers/mssql/mssql_driver.php | 6 +- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 6 +- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 6 +- system/database/drivers/sqlsrv/sqlsrv_driver.php | 6 +- 6 files changed, 78 insertions(+), 57 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 43ea10023..a327f4ad9 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1128,8 +1128,8 @@ abstract class CI_DB_driver { } return 'UPDATE '.$table.' SET '.implode(', ', $valstr) - .$this->_compile_where() - .(empty($this->qb_orderby) ? '' : ' ORDER BY '.implode(', ', $this->qb_orderby)) + .$this->_compile_wh('qb_where') + .$this->_compile_order_by() .($this->qb_limit ? ' LIMIT '.$this->qb_limit : ''); } diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 6c247f957..416132e16 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -948,54 +948,50 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * Sets the ORDER BY value * * @param string - * @param string direction: asc or desc + * @param string direction: ASC or DESC * @param bool enable field name escaping * @return object */ public function order_by($orderby, $direction = '', $escape = NULL) { - if (strtolower($direction) === 'random') + $direction = trim($direction); + + if (strtolower($direction) === 'random' OR $orderby === $this->_random_keyword) + { + // Random ordered results don't need a field name + $orderby = $this->_random_keyword; + $direction = ''; + } + elseif (empty($orderby)) { - $orderby = ''; // Random results want or don't need a field name - $direction = $this->_random_keyword; + return $this; } - elseif (trim($direction) !== '') + elseif ($direction !== '') { - $direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' '.$direction : ' ASC'; + $direction = in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE) ? ' '.$direction : ''; } is_bool($escape) OR $escape = $this->_protect_identifiers; - if ($escape === TRUE && strpos($orderby, ',') !== FALSE) + if ($escape === FALSE) { - $temp = array(); - foreach (explode(',', $orderby) as $part) - { - $part = trim($part); - if ( ! in_array($part, $this->qb_aliased_tables)) - { - $part = preg_match('/^(.+)\s+(ASC|DESC)$/i', $part, $matches) - ? $this->protect_identifiers(rtrim($matches[1])).' '.$matches[2] - : $this->protect_identifiers($part); - } - - $temp[] = $part; - } - - $orderby = implode(', ', $temp); + $qb_orderby[] = array(array('field' => $orderby, 'direction' => $direction, $escape => FALSE)); } - elseif ($direction !== $this->_random_keyword && $escape === TRUE) + else { - $orderby = preg_match('/^(.+)\s+(ASC|DESC)$/i', $orderby, $matches) - ? $this->protect_identifiers(rtrim($matches[1])).' '.$matches[2] - : $this->protect_identifiers($orderby); + $qb_orderby = array(); + foreach (explode(',', $orderby) as $field) + { + $qb_orderby[] = ($direction === '' && preg_match('/\s+(ASC|DESC)$/i', rtrim($field), $match, PREG_OFFSET_CAPTURE)) + ? array('field' => ltrim(substr($field, 0, $match[0][1])), 'direction' => ' '.$match[1][0], 'escape' => TRUE) + : array('field' => trim($field), 'direction' => $direction, 'escape' => TRUE); + } } - $this->qb_orderby[] = $orderby_statement = $orderby.$direction; - + $this->qb_orderby = array_merge($this->qb_orderby, $qb_orderby); if ($this->qb_caching === TRUE) { - $this->qb_cache_orderby[] = $orderby_statement; + $this->qb_cache_orderby = array_merge($this->qb_cache_orderby, $qb_orderby); $this->qb_cache_exists[] = 'orderby'; } @@ -2023,20 +2019,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $sql .= "\n".implode("\n", $this->qb_join); } - // WHERE - $sql .= $this->_compile_wh('qb_where'); - - // GROUP BY - $sql .= $this->_compile_group_by(); - - // HAVING - $sql .= $this->_compile_wh('qb_having'); - - // ORDER BY - if (count($this->qb_orderby) > 0) - { - $sql .= "\nORDER BY ".implode(', ', $this->qb_orderby); - } + $sql .= $this->_compile_wh('qb_where') + .$this->_compile_group_by() + .$this->_compile_wh('qb_having') + .$this->_compile_order_by(); // ORDER BY // LIMIT if ($this->qb_limit) @@ -2136,6 +2122,41 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Compile ORDER BY + * + * Escapes identifiers in ORDER BY statements at execution time. + * + * Required so that aliases are tracked properly, regardless of wether + * order_by() is called prior to from(), join() and dbprefix is added + * only if needed. + * + * @return string SQL statement + */ + protected function _compile_order_by() + { + if (count($this->qb_orderby) > 0) + { + $sql = "\nORDER BY "; + + for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) + { + if ($this->qb_orderby[$i]['escape'] !== FALSE) + { + $this->qb_orderby[$i]['field'] = $this->protect_identifiers($field); + } + + $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; + } + + $sql .= implode(', ', $this->qb_orderby); + } + + return ''; + } + + // -------------------------------------------------------------------- + /** * Object to Array * diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index bfc82a6c2..edc6a8480 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -453,13 +453,13 @@ class CI_DB_mssql_driver extends CI_DB { // however an ORDER BY clause is required for it to work if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = trim($this->_compile_order_by()); + $orderby = $this->_compile_order_by(); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" - .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index ad699ce23..d6465cda2 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -222,13 +222,13 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { // however an ORDER BY clause is required for it to work if (version_compare($this->version(), '9', '>=') && $this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = trim($this->_compile_order_by()); + $orderby = $this->_compile_order_by(); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" - .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 399d134af..4b5747d90 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -256,13 +256,13 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { // An ORDER BY clause is required for ROW_NUMBER() to work if ($this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = trim($this->_compile_order_by()); + $orderby = $this->_compile_order_by(); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" - .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 4eb12f910..badbb8e90 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -454,13 +454,13 @@ class CI_DB_sqlsrv_driver extends CI_DB { // An ORDER BY clause is required for ROW_NUMBER() to work if ($this->qb_offset && ! empty($this->qb_orderby)) { - $orderby = trim($this->_compile_order_by()); + $orderby = $this->_compile_order_by(); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" - .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) + .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) ."\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } -- cgit v1.2.3-24-g4f1b From 822317b2a8a9872819cd22de6782b44f5c267d2f Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 16:00:32 +0300 Subject: Add back a removed paramter description --- system/database/DB_driver.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index a327f4ad9..371b6db96 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1118,6 +1118,7 @@ abstract class CI_DB_driver { * Generates a platform-specific update string from the supplied data * * @param string the table name + * @param array the update data * @return string */ protected function _update($table, $values) -- cgit v1.2.3-24-g4f1b From e8be24b1c4bc3dd6fb78133d15857e2b23972c5b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 19 Jul 2012 16:11:17 +0300 Subject: Fix CI_DB_driver::_get_operator() --- system/database/DB_driver.php | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index 371b6db96..f848cfe4e 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1157,29 +1157,28 @@ abstract class CI_DB_driver { */ protected function _get_operator($str) { - static $_operators = array( - '\s*(?:<|>|!)?=\s*', // =, <=, >=, != - '\s*<>?\s*', // <, <> - '\s*>\s*', // > - '\s+IS NULL', // IS NULL - '\s+IS NOT NULL', // IS NOT NULL - '\s+BETWEEN\s+\S+\s+AND\s+\S+', // BETWEEN value AND value - '\s+IN\s*\([^\)]+\)', // IN(list) - '\s+NOT IN\s*\([^\)]+\)' // NOT IN (list) - ); + static $_operators; - static $_like = array( - '\s+LIKE\s+\S+', // LIKE 'expr' - '\s+NOT LIKE\s+\S+', // NOT LIKE 'expr' - ); - - if ($this->_like_escape_str !== '') + if (empty($_operators)) { - $_like[0] .= preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))); - $_like[1] .= preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))); - } + $_les = ($this->_like_escape_str !== '') + ? preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))) + : ''; - $_operators = array_merge($_operators, $_like); + $_operators = array( + '\s*(?:<|>|!)?=\s*', // =, <=, >=, != + '\s*<>?\s*', // <, <> + '\s*>\s*', // > + '\s+IS NULL', // IS NULL + '\s+IS NOT NULL', // IS NOT NULL + '\s+BETWEEN\s+\S+\s+AND\s+\S+', // BETWEEN value AND value + '\s+IN\s*\([^\)]+\)', // IN(list) + '\s+NOT IN\s*\([^\)]+\)', // NOT IN (list) + '\s+LIKE\s+\S+'.$_les, // LIKE 'expr'[ ESCAPE '%s'] + '\s+NOT LIKE\s+\S+'.$_les // NOT LIKE 'expr'[ ESCAPE '%s'] + ); + + } return preg_match('/'.implode('|', $_operators).'/i', $str, $match) ? $match[0] : FALSE; -- cgit v1.2.3-24-g4f1b From a5a71359a5b320b0dc35fabfeb3e74e97a466a10 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 20 Jul 2012 19:36:43 -0300 Subject: Added support for IP Address Range Masks (e.g. 192.168.137.0/24) to the Proxy IPs config option --- system/core/Input.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 162e40c85..c0c85a5e8 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -330,10 +330,27 @@ class CI_Input { if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) { + $hasRanges = strpos($proxies, '/') !== false; $proxies = preg_split('/[\s,]/', config_item('proxy_ips'), -1, PREG_SPLIT_NO_EMPTY); $proxies = is_array($proxies) ? $proxies : array($proxies); - - $this->ip_address = in_array($_SERVER['REMOTE_ADDR'], $proxies) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; + + if ($hasRanges) { + $longIP = ip2long($_SERVER['REMOTE_ADDR']); + $bit32 = 1 << 32; + + foreach($proxies as $ip) { + list($address, $maskLength) = explode('/', $ip); + + $bitmask = $bit32 - (1 << (32 - (int)$maskLength)); + + if (($longIP & $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']; + } } elseif ( ! $this->server('HTTP_CLIENT_IP') && $this->server('REMOTE_ADDR')) { -- cgit v1.2.3-24-g4f1b From 8711aebec411ea31ae650202f49908de1f313689 Mon Sep 17 00:00:00 2001 From: Przemyslaw Tomaszewski Date: Sun, 22 Jul 2012 03:28:41 +0200 Subject: Comment fix. Html5 is most popular these days and should be added to comment. Also - information that there are more doctypes than specified in comment was not included. --- system/helpers/html_helper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 68ce70248..6fabf9c05 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -242,9 +242,9 @@ if ( ! function_exists('doctype')) * * Generates a page document type declaration * - * Valid options are xhtml-11, xhtml-strict, xhtml-trans, xhtml-frame, - * html4-strict, html4-trans, and html4-frame. Values are saved in the - * doctypes config file. + * Examples of valid options: html5, xhtml-11, xhtml-strict, xhtml-trans, + * xhtml-frame, html4-strict, html4-trans, and html4-frame. + * All values are saved in the doctypes config file. * * @param string type The doctype to be generated * @return string -- cgit v1.2.3-24-g4f1b From 74cb495239927d5ea876459b179954e5bcc0488c Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sat, 21 Jul 2012 22:55:58 -0400 Subject: Removing $reduce_linebreaks in auto_typography helper. Fixes #1642 I researched this back to a commit by @derekjones but couldn't find any history on what the reason for it was or why it was even added. Signed-off-by: Eric Barnes --- system/helpers/typography_helper.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index af9d16a89..9dbba0679 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -65,11 +65,11 @@ if ( ! function_exists('auto_typography')) * @param bool whether to reduce multiple instances of double newlines to two * @return string */ - function auto_typography($str, $strip_js_event_handlers = TRUE, $reduce_linebreaks = FALSE) + function auto_typography($str, $reduce_linebreaks = FALSE) { $CI =& get_instance(); $CI->load->library('typography'); - return $CI->typography->auto_typography($str, $strip_js_event_handlers, $reduce_linebreaks); + return $CI->typography->auto_typography($str, $reduce_linebreaks); } } -- cgit v1.2.3-24-g4f1b From 8960acf4fae56fd7b62a451ce8ea571c0e631ed1 Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Mon, 23 Jul 2012 09:05:49 -0300 Subject: Update system/core/Input.php --- system/core/Input.php | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index c0c85a5e8..968a42a9a 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -330,24 +330,30 @@ class CI_Input { if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) { - $hasRanges = 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 ($hasRanges) { - $longIP = ip2long($_SERVER['REMOTE_ADDR']); - $bit32 = 1 << 32; - - foreach($proxies as $ip) { - list($address, $maskLength) = explode('/', $ip); - - $bitmask = $bit32 - (1 << (32 - (int)$maskLength)); - - if (($longIP & $bitmask) == $address) { + if ($has_ranges) + { + $long_ip = ip2long($_SERVER['REMOTE_ADDR']); + $bit_32 = 1 << 32; + + // Go through each of the IP Addresses to check for and + // test against range notation + foreach($proxies as $ip) + { + list($address, $mask_length) = explode('/', $ip); + + // Generate the bitmask for a 32 bit IP 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']; } -- cgit v1.2.3-24-g4f1b From ede49ba66b127535f3430e20aac72ceed2c4611a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 23 Jul 2012 16:06:36 +0300 Subject: Fix a bug in CI_DB_sqlsrv_driver::affected_rows() --- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 8bd18bd76..bda450e88 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -225,7 +225,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ public function affected_rows() { - return sqlrv_rows_affected($this->result_id); + return sqlsrv_rows_affected($this->result_id); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 1288fe36214e0c8a22edec16da209081930e17c9 Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 23 Jul 2012 16:22:06 +0200 Subject: output->_display_cache() optimization faster method to remove the timestamp from the content to be served --- system/core/Output.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index 5ec8c4bc0..2bf4e998f 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -575,7 +575,7 @@ class CI_Output { } // Display the cache - $this->_display(str_replace($match[0], '', $cache)); + $this->_display(substr($cache, strlen($match[0]))); log_message('debug', 'Cache file is current. Sending it to browser.'); return TRUE; } -- cgit v1.2.3-24-g4f1b From d9384ad6472dd042a897a9b80d78bbf92a794c0f Mon Sep 17 00:00:00 2001 From: vlakoff Date: Mon, 23 Jul 2012 17:06:36 +0200 Subject: output->_display_cache() simplifications remove an unneeded regex capturing group and an unneeded trim() --- system/core/Output.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Output.php b/system/core/Output.php index 2bf4e998f..9842f834d 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 = trim(str_replace('TS--->', '', $match[1])); + $expire = str_replace('TS--->', '', $match[0]); // Has the file expired? if ($_SERVER['REQUEST_TIME'] >= $expire && is_really_writable($cache_path)) -- 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(-) (limited to 'system') 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(-) (limited to 'system') 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 f0ecb55dfe8dbfaf4c65dbe9d7e1bba8c131ebf4 Mon Sep 17 00:00:00 2001 From: Phil Sturgeon Date: Thu, 26 Jul 2012 17:00:33 +0200 Subject: If $htdocs = FALSE delete_files would never unlink --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index 3834d4895..b6c95d554 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -124,7 +124,7 @@ if ( ! function_exists('delete_files')) { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs); } - elseif ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) + elseif ($htdocs === FALSE OR ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))) { @unlink($path.DIRECTORY_SEPARATOR.$filename); } -- cgit v1.2.3-24-g4f1b From 27228c97d6f2bc44cf8913c2b0d2e2ee439eb696 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 27 Jul 2012 10:36:29 +0300 Subject: Improve change from f0ecb55dfe8dbfaf4c65dbe9d7e1bba8c131ebf4 and add changelog entries for pull #1654 --- system/helpers/file_helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index b6c95d554..e68bb7f7a 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -124,7 +124,7 @@ if ( ! function_exists('delete_files')) { delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1, $htdocs); } - elseif ($htdocs === FALSE OR ($htdocs === TRUE && ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename))) + elseif ($htdocs !== TRUE OR ! preg_match('/^(\.htaccess|index\.(html|htm|php)|web\.config)$/i', $filename)) { @unlink($path.DIRECTORY_SEPARATOR.$filename); } -- cgit v1.2.3-24-g4f1b From 62ab8b24fc37a25eab9205c46321fa41729e5faf Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sat, 28 Jul 2012 14:57:04 -0400 Subject: Adding optional attributes as array or object for html helper --- system/helpers/html_helper.php | 59 ++++++++++++++++++++++++++++-------------- 1 file changed, 40 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 6fabf9c05..96234bb02 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -51,7 +51,7 @@ if ( ! function_exists('heading')) */ function heading($data = '', $h = '1', $attributes = '') { - return ''.$data.''; + return ''.$data.''; } } @@ -119,23 +119,8 @@ if ( ! function_exists('_list')) // Set the indentation based on the depth $out = str_repeat(' ', $depth); - // Were any attributes submitted? If so generate a string - if (is_array($attributes)) - { - $atts = ''; - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } - $attributes = $atts; - } - elseif (is_string($attributes) && strlen($attributes) > 0) - { - $attributes = ' '.$attributes; - } - // Write the opening list tag - $out .= '<'.$type.$attributes.">\n"; + $out .= '<'.$type._html_attributes_to_string($attributes).">\n"; // Cycle through the list elements. If an array is // encountered we will recursively call _list() @@ -191,9 +176,10 @@ if ( ! function_exists('img')) * * @param mixed * @param bool + * @param mixed * @return string */ - function img($src = '', $index_page = FALSE) + function img($src = '', $index_page = FALSE, $attributes = '') { if ( ! is_array($src) ) { @@ -229,7 +215,7 @@ if ( ! function_exists('img')) } } - return $img.'/>'; + return $img._html_attributes_to_string($attributes).'/>'; } } @@ -407,5 +393,40 @@ if ( ! function_exists('nbs')) } } +if ( ! function_exists('_html_attributes_to_string')) +{ + /** + * Attributes To String + * + * Helper function used to convert array or object of attributes to a string + * + * @param mixed + * @param bool + * @return string + */ + function _html_attributes_to_string($attributes) + { + if (is_object($attributes) && count($attributes) > 0) + { + $attributes = (array) $attributes; + } + + if (is_array($attributes) && count($attributes) > 0) + { + $atts = ''; + foreach ($attributes as $key => $val) + { + $atts .= ' '.$key.'="'.$val.'"'; + } + return $atts; + } + elseif (is_string($attributes) && strlen($attributes) > 0) + { + return ' '.$attributes; + } + + return $attributes; + } +} /* End of file html_helper.php */ /* Location: ./system/helpers/html_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From acedd2b1a37b22cb04b01038f21876ddfe38b83a Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 29 Jul 2012 00:15:40 -0400 Subject: Adding a common stringify_attributes function for dealing with attributes through out various helpers. Signed-off-by: Eric Barnes --- system/core/Common.php | 49 +++++++++++++++++++++++++++++++++++++++++ system/helpers/date_helper.php | 17 +------------- system/helpers/html_helper.php | 41 +++------------------------------- system/helpers/url_helper.php | 50 ++++-------------------------------------- 4 files changed, 57 insertions(+), 100 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 06b162264..d4d01f813 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -598,5 +598,54 @@ if ( ! function_exists('html_escape')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('_stringify_attributes')) +{ + /** + * Attributes To String + * + * Helper function used to convert an array or object of + * attributes to a string + * + * @param mixed + * @return string + */ + function _stringify_attributes($attributes, $js = FALSE) + { + if (is_object($attributes) && count($attributes) > 0) + { + $attributes = (array) $attributes; + } + + if (is_array($attributes)) + { + $atts = ''; + if (count($attributes) === 0) + { + return $atts; + } + foreach ($attributes as $key => $val) + { + if ($js) + { + $atts .= $key.'='.$val.','; + } + else + { + $atts .= ' '.$key.'="'.$val.'"'; + } + } + return rtrim($atts, ','); + } + elseif (is_string($attributes) && strlen($attributes) > 0) + { + return ' '.$attributes; + } + + return $attributes; + } +} + /* End of file Common.php */ /* Location: ./system/core/Common.php */ \ No newline at end of file diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index a45b3d7ac..a792f09a2 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -575,22 +575,7 @@ if ( ! function_exists('timezone_menu')) $menu .= ' class="'.$class.'"'; } - // Generate a string from the attributes submitted, if any - if (is_array($attributes)) - { - $atts = ''; - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } - $attributes = $atts; - } - elseif (is_string($attributes) && strlen($attributes) > 0) - { - $attributes = ' '.$attributes; - } - - $menu .= $attributes.">\n"; + $menu .= _stringify_attributes($attributes).">\n"; foreach (timezones() as $key => $val) { diff --git a/system/helpers/html_helper.php b/system/helpers/html_helper.php index 96234bb02..9843e804e 100644 --- a/system/helpers/html_helper.php +++ b/system/helpers/html_helper.php @@ -51,7 +51,7 @@ if ( ! function_exists('heading')) */ function heading($data = '', $h = '1', $attributes = '') { - return ''.$data.''; + return ''.$data.''; } } @@ -120,7 +120,7 @@ if ( ! function_exists('_list')) $out = str_repeat(' ', $depth); // Write the opening list tag - $out .= '<'.$type._html_attributes_to_string($attributes).">\n"; + $out .= '<'.$type._stringify_attributes($attributes).">\n"; // Cycle through the list elements. If an array is // encountered we will recursively call _list() @@ -215,7 +215,7 @@ if ( ! function_exists('img')) } } - return $img._html_attributes_to_string($attributes).'/>'; + return $img._stringify_attributes($attributes).'/>'; } } @@ -393,40 +393,5 @@ if ( ! function_exists('nbs')) } } -if ( ! function_exists('_html_attributes_to_string')) -{ - /** - * Attributes To String - * - * Helper function used to convert array or object of attributes to a string - * - * @param mixed - * @param bool - * @return string - */ - function _html_attributes_to_string($attributes) - { - if (is_object($attributes) && count($attributes) > 0) - { - $attributes = (array) $attributes; - } - - if (is_array($attributes) && count($attributes) > 0) - { - $atts = ''; - foreach ($attributes as $key => $val) - { - $atts .= ' '.$key.'="'.$val.'"'; - } - return $atts; - } - elseif (is_string($attributes) && strlen($attributes) > 0) - { - return ' '.$attributes; - } - - return $attributes; - } -} /* End of file html_helper.php */ /* Location: ./system/helpers/html_helper.php */ \ No newline at end of file diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index 39e6343a6..57208c948 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -165,7 +165,7 @@ if ( ! function_exists('anchor')) if ($attributes !== '') { - $attributes = _parse_attributes($attributes); + $attributes = _stringify_attributes($attributes); } return ''.$title.''; @@ -221,10 +221,10 @@ if ( ! function_exists('anchor_popup')) unset($attributes[$key]); } - $attributes = empty($attributes) ? '' : _parse_attributes($attributes); + $attributes = _stringify_attributes($attributes); return ''.$title.''; } } @@ -250,7 +250,7 @@ if ( ! function_exists('mailto')) $title = $email; } - return ''.$title.''; + return ''.$title.''; } } @@ -560,47 +560,5 @@ if ( ! function_exists('redirect')) } } -// ------------------------------------------------------------------------ - -if ( ! function_exists('_parse_attributes')) -{ - /** - * Parse out the attributes - * - * Some of the functions use this - * - * @param array - * @param bool - * @return string - */ - function _parse_attributes($attributes, $javascript = FALSE) - { - if (is_string($attributes)) - { - return ($attributes !== '') ? ' '.$attributes : ''; - } - - $att = ''; - foreach ($attributes as $key => $val) - { - if ($javascript === TRUE) - { - $att .= $key.'='.$val.','; - } - else - { - $att .= ' '.$key.'="'.$val.'"'; - } - } - - if ($javascript === TRUE && $att !== '') - { - return substr($att, 0, -1); - } - - return $att; - } -} - /* End of file url_helper.php */ /* Location: ./system/helpers/url_helper.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 19204f96b8abc1322feb0f660240ed7abb69026b Mon Sep 17 00:00:00 2001 From: Eric Barnes Date: Sun, 29 Jul 2012 00:18:07 -0400 Subject: Refactored _stringify_attributes function Signed-off-by: Eric Barnes --- system/core/Common.php | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index d4d01f813..7c46c590a 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -603,47 +603,45 @@ if ( ! function_exists('html_escape')) if ( ! function_exists('_stringify_attributes')) { /** - * Attributes To String + * Stringify attributes for use in html tags. * - * Helper function used to convert an array or object of + * Helper function used to convert a string, array, or object of * attributes to a string * - * @param mixed + * @param mixed string, array, object + * @param bool * @return string */ function _stringify_attributes($attributes, $js = FALSE) { - if (is_object($attributes) && count($attributes) > 0) + if (is_string($attributes)) + { + return strlen($attributes) > 0 ? ' '.$attributes : $attributes; + } + + if (is_object($attributes)) { $attributes = (array) $attributes; } - if (is_array($attributes)) + if (count($attributes) === 0) + { + return; + } + + $atts = ''; + foreach ($attributes as $key => $val) { - $atts = ''; - if (count($attributes) === 0) + if ($js) { - return $atts; + $atts .= $key.'='.$val.','; } - foreach ($attributes as $key => $val) + else { - if ($js) - { - $atts .= $key.'='.$val.','; - } - else - { - $atts .= ' '.$key.'="'.$val.'"'; - } + $atts .= ' '.$key.'="'.$val.'"'; } - return rtrim($atts, ','); - } - elseif (is_string($attributes) && strlen($attributes) > 0) - { - return ' '.$attributes; } - - return $attributes; + return rtrim($atts, ','); } } -- cgit v1.2.3-24-g4f1b From a1abadaab34d8d08c54557c7e60d12eb624b72fe Mon Sep 17 00:00:00 2001 From: Chad Furman Date: Sun, 29 Jul 2012 01:03:50 -0400 Subject: refactored (crunched down) _stringify_attributes --- system/core/Common.php | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 06b162264..5cd3961d1 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -598,5 +598,44 @@ if ( ! function_exists('html_escape')) } } +// ------------------------------------------------------------------------ + +if ( ! function_exists('_stringify_attributes')) +{ + /** + * Stringify attributes for use in html tags. + * + * Helper function used to convert a string, array, or object of + * attributes to a string + * + * @param mixed string, array, object + * @param bool + * @return string + */ + function _stringify_attributes($attributes, $js = FALSE) + { + $atts = null; + + if (empty($attributes)) + { + return $atts; + } + + if (is_string($attributes)) + { + return ' '.$attributes; + } + + $attributes = (array) $attributes; + + foreach ($attributes as $key => $val) + { + $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"'; + } + + return rtrim($atts, ','); + } +} + /* End of file Common.php */ -/* Location: ./system/core/Common.php */ \ No newline at end of file +/* Location: ./system/core/Common.php */ -- cgit v1.2.3-24-g4f1b From b901e736a811907cea99dda9d06f656f526f5090 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 30 Jul 2012 09:44:57 +0100 Subject: After sending an email clear the parameters --- system/libraries/Email.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fdb9be4da..9d80f0720 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1257,11 +1257,15 @@ class CI_Email { if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size) { - return $this->batch_bcc_send(); + $result = $this->batch_bcc_send(); + $this->clear(); + return $result; } $this->_build_message(); - return $this->_spool_email(); + $result = $this->_spool_email(); + $this->clear(); + return $result; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From d7bc8d04e5c13bbafe3bf10ca2634c1f8481ed53 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 30 Jul 2012 09:46:20 +0100 Subject: New parameter to automatically clear the parameters --- system/libraries/Email.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 9d80f0720..8239862a9 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1238,7 +1238,7 @@ class CI_Email { * * @return bool */ - public function send() + public function send($auto_clear = TRUE) { if ($this->_replyto_flag === FALSE) { @@ -1258,13 +1258,23 @@ class CI_Email { if ($this->bcc_batch_mode && count($this->_bcc_array) > $this->bcc_batch_size) { $result = $this->batch_bcc_send(); - $this->clear(); + + if ($auto_clear) + { + $this->clear(); + } + return $result; } $this->_build_message(); $result = $this->_spool_email(); - $this->clear(); + + if ($auto_clear) + { + $this->clear(); + } + return $result; } -- cgit v1.2.3-24-g4f1b From a87aab39488367c18b9e60d2020665b17b35f4b1 Mon Sep 17 00:00:00 2001 From: Alex Bilbie Date: Mon, 30 Jul 2012 09:50:37 +0100 Subject: Only clear if request was successful --- system/libraries/Email.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8239862a9..196a4b36c 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1259,7 +1259,7 @@ class CI_Email { { $result = $this->batch_bcc_send(); - if ($auto_clear) + if ($result && $auto_clear) { $this->clear(); } @@ -1270,11 +1270,11 @@ class CI_Email { $this->_build_message(); $result = $this->_spool_email(); - if ($auto_clear) + if ($result && $auto_clear) { $this->clear(); } - + return $result; } -- cgit v1.2.3-24-g4f1b From bdb99999195711903af712fab58fdf4ef3da72ad Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 30 Jul 2012 17:38:05 +0300 Subject: Some clean-up and style changes --- system/core/Common.php | 18 +++++++++--------- system/libraries/Email.php | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 5cd3961d1..57374b07d 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -603,18 +603,18 @@ if ( ! function_exists('html_escape')) if ( ! function_exists('_stringify_attributes')) { /** - * Stringify attributes for use in html tags. + * Stringify attributes for use in HTML tags. * - * Helper function used to convert a string, array, or object of - * attributes to a string + * Helper function used to convert a string, array, or object + * of attributes to a string. * - * @param mixed string, array, object - * @param bool - * @return string + * @param mixed string, array, object + * @param bool + * @return string */ function _stringify_attributes($attributes, $js = FALSE) { - $atts = null; + $atts = NULL; if (empty($attributes)) { @@ -632,10 +632,10 @@ if ( ! function_exists('_stringify_attributes')) { $atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"'; } - + return rtrim($atts, ','); } } /* End of file Common.php */ -/* Location: ./system/core/Common.php */ +/* Location: ./system/core/Common.php */ \ No newline at end of file diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 196a4b36c..8fd7a79e7 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1269,7 +1269,7 @@ class CI_Email { $this->_build_message(); $result = $this->_spool_email(); - + if ($result && $auto_clear) { $this->clear(); -- 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(-) (limited to 'system') 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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(+) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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 28ff29272f4ac6815354878534493016ca31582a Mon Sep 17 00:00:00 2001 From: Michiel Vugteveen Date: Tue, 14 Aug 2012 10:55:46 +0200 Subject: fix issue 1706 --- system/helpers/download_helper.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/helpers/download_helper.php b/system/helpers/download_helper.php index 09c4de578..0232adfe4 100644 --- a/system/helpers/download_helper.php +++ b/system/helpers/download_helper.php @@ -95,7 +95,10 @@ if ( ! function_exists('force_download')) } // Clean output buffer - ob_clean(); + if (ob_get_level() !== 0) + { + ob_clean(); + } // Generate the server headers header('Content-Type: '.$mime); -- cgit v1.2.3-24-g4f1b From b453e16668c70b0eb02b5ae69cd3196d735421f8 Mon Sep 17 00:00:00 2001 From: Bruno Barão Date: Tue, 14 Aug 2012 18:40:18 +0100 Subject: Fix email headers when using long email subjects and \r\n as crlf. --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 8fd7a79e7..b922cb1c0 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1228,7 +1228,7 @@ class CI_Email { // wrap each line with the shebang, charset, and transfer encoding // the preceding space on successive lines is required for header "folding" - return trim(preg_replace('/^(.*)$/m', ' =?'.$this->charset.'?Q?$1?=', $output.$temp)); + return trim(preg_replace('/^(.*?)(\n|\r)*$/m', ' =?'.$this->charset.'?Q?$1?=$2', $output.$temp)); } // -------------------------------------------------------------------- -- 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(-) (limited to 'system') 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 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 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'system') 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; } -- 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(-) (limited to 'system') 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 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(+) (limited to 'system') 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(-) (limited to 'system') 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 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 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'system') 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); -- 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(-) (limited to 'system') 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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 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(+) (limited to 'system') 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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(-) (limited to 'system') 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(-) (limited to 'system') 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') 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']); -- 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(-) (limited to 'system') 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 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'system') 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(); -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') 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'; } -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') 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']); -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') 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; } -- 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(-) (limited to 'system') 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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 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(-) (limited to 'system') 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(+) (limited to 'system') 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(-) (limited to 'system') 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 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 ---- 16 files changed, 6 insertions(+), 55 deletions(-) (limited to 'system') 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 -- 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 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'system') 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')) -- 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 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'system') 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); } } } -- 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(-) (limited to 'system') 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(-) (limited to 'system') 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 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') 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; -- 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 (limited to 'system') 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 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(-) (limited to 'system') 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 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 +++++++ 1 file changed, 7 insertions(+) (limited to 'system') 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 -- 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 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'system') 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']); -- 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') 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; } -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') 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); } // -------------------------------------------------------------------- -- 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(-) (limited to 'system') 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 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 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'system') 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); } -- cgit v1.2.3-24-g4f1b From 9ac557f2473844f3c2207189f371f827dbaddb71 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 6 Oct 2012 20:27:57 +0300 Subject: Add IPv6 and array() support for *proxy_ips* configuration --- system/core/Input.php | 141 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 99 insertions(+), 42 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 657fce625..4a0caa5b5 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -328,60 +328,117 @@ class CI_Input { return $this->ip_address; } - if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) + $proxy_ips = config_item('proxy_ips'); + if (empty($proxy_ips)) { - $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); + $proxy_ips = FALSE; + } + elseif ( ! is_array($proxy_ips)) + { + $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips)); + } - if ($has_ranges) - { - $long_ip = ip2long($_SERVER['REMOTE_ADDR']); - $bit_32 = 1 << 32; + $this->ip_address = $this->server('REMOTE_ADDR'); - // Go through each of the IP Addresses to check for and - // test against range notation - foreach ($proxies as $ip) + if ($proxy_ips) + { + foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header) + { + if (($spoof = $this->server($header)) !== NULL) { - list($address, $mask_length) = explode('/', $ip, 2); + // Some proxies typically list the whole chain of IP + // addresses through which the client has reached us. + // e.g. client_ip, proxy_ip1, proxy_ip2, etc. + if (strpos($spoof, ',') !== FALSE) + { + $spoof = explode(',', $spoof, 2); + $spoof = $spoof[0]; + } - // Generate the bitmask for a 32 bit IP Address - $bitmask = $bit_32 - (1 << (32 - (int) $mask_length)); - if (($long_ip & $bitmask) === $address) + if ( ! $this->valid_ip($spoof)) + { + $spoof = NULL; + } + else { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; break; } } - } - else + + if ($spoof !== NULL) { - $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')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('REMOTE_ADDR') && $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } + for ($i = 0, $c = count($proxy_ips), $separator = (strlen($ip) === 32 ? '.' : ':'); $i < $c; $i++) + { + // Check if we have an IP address or a subnet + if (strpos($proxy_ips[$i], '/') === FALSE) + { + // An IP address (and not a subnet) is specified. + // We can compare right away. + if ($proxy_ips[$i] === $this->ip_address) + { + $this->ip_address = $spoof; + break; + } + + continue; + } - if ($this->ip_address === FALSE) - { - return $this->ip_address = '0.0.0.0'; + // We have a subnet ... now the heavy lifting begins + isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.'; + + // If the proxy entry doesn't match the IP protocol - skip it + if (strpos($proxy_ips[$i], $separator) === FALSE) + { + continue; + } + + // Convert the REMOTE_ADDR IP address to binary, if needed + if ( ! isset($ip, $convert_func)) + { + if ($separator === ':') + { + // Make sure we're have the "full" IPv6 format + $ip = str_replace('::', str_repeat(':', 9 - substr_count($this->ip_address, ':')), $this->ip_address); + $convert_func = is_php('5.3') + ? function ($value) + { + return str_pad(base_convert($value, 16, 2), 16, '0', STR_PAD_LEFT); + } + : create_function('$value', 'return str_pad(base_convert($value, 16, 2), 16, "0", STR_PAD_LEFT);'); + } + else + { + $ip = $this->ip_address; + $convert_func = is_php('5.3') + ? function ($value) + { + return str_pad(decbin($value), 8, '0', STR_PAD_LEFT); + } + : create_function('$value', 'return str_pad(decbin($value), 8, "0", STR_PAD_LEFT);'); + } + + $ip = implode(array_map($convert_func, explode($separator, $ip))); + } + + // Split the netmask length off the network address + list($netaddr, $masklen) = explode('/', $proxy_ips[$i], 2); + + // Again, an IPv6 address is most likely in a compressed form + if ($separator === ':') + { + $netaddr = str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr); + } + + // Convert to a binary form and finally compare + $netaddr = implode(array_map($convert_func, explode($separator, $netaddr))); + if (strncmp($ip, $netaddr, $masklen) === 0) + { + $this->ip_address = $spoof; + break; + } + } + } } if (strpos($this->ip_address, ',') !== FALSE) -- 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 ---------------- 16 files changed, 1 insertion(+), 259 deletions(-) (limited to 'system') 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 * -- cgit v1.2.3-24-g4f1b From 51f72cda43e4f7aa9cafbf31181e67c31936a0bd Mon Sep 17 00:00:00 2001 From: Bruno Barão Date: Mon, 8 Oct 2012 16:31:46 +0100 Subject: Fix email headers when using long email subjects and \r\n as crlf. (Part2) - Better expression for the preg_replace. - Added a entry to the changelog. --- system/libraries/Email.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 507067f42..4adf9430f 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1237,7 +1237,7 @@ class CI_Email { // wrap each line with the shebang, charset, and transfer encoding // the preceding space on successive lines is required for header "folding" - return trim(preg_replace('/^(.*?)(\n|\r)*$/m', ' =?'.$this->charset.'?Q?$1?=$2', $output.$temp)); + return trim(preg_replace('/^(.*?)(\r*)$/m', ' =?'.$this->charset.'?Q?$1?=$2', $output.$temp)); } // -------------------------------------------------------------------- @@ -1861,4 +1861,4 @@ class CI_Email { } /* End of file Email.php */ -/* Location: ./system/libraries/Email.php */ \ No newline at end of file +/* Location: ./system/libraries/Email.php */ -- cgit v1.2.3-24-g4f1b From 509885932928b34f22091b59b014ec16c52b4bbe Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 8 Oct 2012 20:46:04 +0300 Subject: [ci skip] Polish changes from pull #1709 --- system/libraries/Email.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 4adf9430f..36bdd1f22 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1861,4 +1861,4 @@ class CI_Email { } /* End of file Email.php */ -/* Location: ./system/libraries/Email.php */ +/* Location: ./system/libraries/Email.php */ \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 70b789990813b5db6d05dc25e2a0ee46008ad00e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 10:36:04 +0300 Subject: Fix issue #1862 --- system/database/DB_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b12042bde..ea2a53eb2 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1363,7 +1363,7 @@ abstract class CI_DB_driver { $call['file'] = str_replace('\\', '/', $call['file']); } - if (isset($call['file'], $call['class']) && strpos($call['file'], $basepath.'database') === FALSE && 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']); -- cgit v1.2.3-24-g4f1b From 7eaa14f144f9aeab8fc388b6bed3390e5f815508 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 11:34:01 +0300 Subject: Alter fix for issue #1257 --- system/database/DB_query_builder.php | 19 ++++++++++++++++++- system/database/drivers/cubrid/cubrid_driver.php | 20 ++++++++++++++++++++ system/database/drivers/mysql/mysql_driver.php | 20 ++++++++++++++++++++ system/database/drivers/mysqli/mysqli_driver.php | 20 ++++++++++++++++++++ .../drivers/pdo/subdrivers/pdo_cubrid_driver.php | 20 ++++++++++++++++++++ .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 20 ++++++++++++++++++++ 6 files changed, 118 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 8bd2ab53c..c77648b38 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1521,6 +1521,23 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * Note: This is only used (and overriden) by MySQL and CUBRID. + * + * @return string + */ + protected function _from_tables() + { + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + /** * Get UPDATE query string * @@ -2040,7 +2057,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 ".implode(', ', $this->qb_from); + $sql .= "\nFROM ".$this->from_tables(); } // Write the "JOIN" portion of the query diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 28724e0e8..8faa15bcf 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -428,6 +428,26 @@ class CI_DB_cubrid_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 6b4d84dfb..98311872b 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -464,6 +464,26 @@ class CI_DB_mysql_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 14949ecda..291ad16f2 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -474,6 +474,26 @@ class CI_DB_mysqli_driver extends CI_DB { // -------------------------------------------------------------------- + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + + // -------------------------------------------------------------------- + /** * Close DB Connection * diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php index eb3714783..788274ad7 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -179,6 +179,26 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver { return 'TRUNCATE '.$table; } + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + } /* End of file pdo_cubrid_driver.php */ diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index b6807026d..698826636 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -207,6 +207,26 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { return 'TRUNCATE '.$table; } + // -------------------------------------------------------------------- + + /** + * FROM tables + * + * Groups tables in FROM clauses if needed, so there is no confusion + * about operator precedence. + * + * @return string + */ + protected function _from_tables() + { + if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + { + return '('.implode(', ', $this->qb_from).')'; + } + + return implode(', ', $this->qb_from); + } + } /* End of file pdo_mysql_driver.php */ -- cgit v1.2.3-24-g4f1b From fce9abe379cd273262d5e3dcbbb169ffd090506a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 11:37:00 +0300 Subject: Really fix that FROM group condition --- system/database/drivers/cubrid/cubrid_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 2 +- system/database/drivers/mysqli/mysqli_driver.php | 2 +- system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php | 2 +- system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 8faa15bcf..01d0ee39e 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -438,7 +438,7 @@ class CI_DB_cubrid_driver extends CI_DB { */ protected function _from_tables() { - if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 98311872b..7262591ee 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -474,7 +474,7 @@ class CI_DB_mysql_driver extends CI_DB { */ protected function _from_tables() { - if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 291ad16f2..b5a1e26ed 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -484,7 +484,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ protected function _from_tables() { - if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php index 788274ad7..cb18a5c10 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_cubrid_driver.php @@ -191,7 +191,7 @@ class CI_DB_pdo_cubrid_driver extends CI_DB_pdo_driver { */ protected function _from_tables() { - if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 698826636..42446889a 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -219,7 +219,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { */ protected function _from_tables() { - if ( ! empty($this->qb_join) && count($this->qb_from) > 0) + if ( ! empty($this->qb_join) && count($this->qb_from) > 1) { return '('.implode(', ', $this->qb_from).')'; } -- cgit v1.2.3-24-g4f1b From e78f81537c0859c6ee5b80a09fe63fa946122f01 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 11:38:38 +0300 Subject: Missed an underscore ... doh --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index c77648b38..54510ec2e 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2057,7 +2057,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(); + $sql .= "\nFROM ".$this->_from_tables(); } // Write the "JOIN" portion of the query -- cgit v1.2.3-24-g4f1b From e45ad2b74d9534395616d661cf4656d6f259943b Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 13:11:15 +0300 Subject: Merge changes from 2.1-stable --- system/core/Input.php | 97 +++++++++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 49 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 657fce625..4bb08f808 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -328,66 +328,65 @@ class CI_Input { return $this->ip_address; } - if (config_item('proxy_ips') != '' && $this->server('HTTP_X_FORWARDED_FOR') && $this->server('REMOTE_ADDR')) - { - $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); + $this->ip_address = $_SERVER['REMOTE_ADDR']; + $proxy_ips = config_item('proxy_ips'); - if ($has_ranges) + if ( ! empty($proxy_ips)) + { + foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header) { - $long_ip = ip2long($_SERVER['REMOTE_ADDR']); - $bit_32 = 1 << 32; - - // Go through each of the IP Addresses to check for and - // test against range notation - foreach ($proxies as $ip) + if (($spoof = $this->server($header)) !== FALSE) { - list($address, $mask_length) = explode('/', $ip, 2); + // Some proxies typically list the whole chain of IP + // addresses through which the client has reached us. + // e.g. client_ip, proxy_ip1, proxy_ip2, etc. + if (strpos($spoof, ',') !== FALSE) + { + $spoof = explode(',', $spoof, 2); + $spoof = $spoof[0]; + } - // Generate the bitmask for a 32 bit IP Address - $bitmask = $bit_32 - (1 << (32 - (int) $mask_length)); - if (($long_ip & $bitmask) === $address) + if ( ! $this->valid_ip($spoof)) + { + $spoof = FALSE; + } + else { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; break; } } - } - else + + if ($spoof) { - $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')) - { - $this->ip_address = $_SERVER['REMOTE_ADDR']; - } - elseif ($this->server('REMOTE_ADDR') && $this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_CLIENT_IP')) - { - $this->ip_address = $_SERVER['HTTP_CLIENT_IP']; - } - elseif ($this->server('HTTP_X_FORWARDED_FOR')) - { - $this->ip_address = $_SERVER['HTTP_X_FORWARDED_FOR']; - } + $has_ranges = (strpos($proxy_ips, '/') !== FALSE); + $proxy_ips = explode(',', str_replace(' ', '', $proxy_ips)); - if ($this->ip_address === FALSE) - { - return $this->ip_address = '0.0.0.0'; - } + if ($has_ranges) + { + $long_ip = ip2long($_SERVER['REMOTE_ADDR']); + $bit_32 = 1 << 32; - if (strpos($this->ip_address, ',') !== FALSE) - { - $x = explode(',', $this->ip_address); - $this->ip_address = trim($x[0]); + // Go through each of the IP Addresses to check for and + // test against range notation + foreach ($proxy_ips as $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) + { + $this->ip_address = $spoof; + break; + } + } + } + elseif (in_array($_SERVER['REMOTE_ADDR'], $proxy_ips, TRUE)) + { + $this->ip_address = $spoof; + } + } } if ( ! $this->valid_ip($this->ip_address)) @@ -545,7 +544,7 @@ class CI_Input { $_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']); // CSRF Protection check - if ($this->_enable_csrf === TRUE) + if ($this->_enable_csrf === TRUE && ! $this->is_cli_request()) { $this->security->csrf_verify(); } -- cgit v1.2.3-24-g4f1b From 9df35b4d23848e831ead765712addd0b845fd8f4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 13:37:58 +0300 Subject: Remove an unnecessary variable initialization --- system/core/Input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index b65509fd7..82482f2aa 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -364,7 +364,7 @@ class CI_Input { if ($spoof) { - for ($i = 0, $c = count($proxy_ips), $separator = (strlen($ip) === 32 ? '.' : ':'); $i < $c; $i++) + for ($i = 0, $c = count($proxy_ips); $i < $c; $i++) { // Check if we have an IP address or a subnet if (strpos($proxy_ips[$i], '/') === FALSE) -- cgit v1.2.3-24-g4f1b From 683b34d6dfcc10bee7703af605875df9229c2bea Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 15:00:00 +0300 Subject: Alter CI_Emai::_prep_quoted_printable() --- system/libraries/Email.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 36bdd1f22..36ecc347d 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -980,7 +980,6 @@ class CI_Email { $this->_finalbody = $body.$this->_prep_quoted_printable($this->_body).$this->newline.$this->newline; - if ($this->_get_protocol() === 'mail') { $this->_header_str .= $hdr; @@ -1100,11 +1099,19 @@ class CI_Email { * Refer to RFC 2045 http://www.ietf.org/rfc/rfc2045.txt * * @param string - * @param int * @return string */ - protected function _prep_quoted_printable($str, $charlim = '') + protected function _prep_quoted_printable($str) { + // RFC 2045 specifies CRLF as "\r\n". + // However, many developers choose to override that and violate + // the RFC rules due to (apparently) a bug in MS Exchange, + // which only works with "\n". + if ($this->crlf === "\r\n" && is_php('5.3')) + { + return quoted_printable_encode($str); + } + // Set the character limit // Don't allow over 76, as that will make servers and MUAs barf // all over quoted-printable data -- cgit v1.2.3-24-g4f1b From 2e3e23053d9748c68fa2c0e11f43af67da8743e8 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 9 Oct 2012 15:52:34 +0300 Subject: Disable Session library under CLI and create a CI singleton to be used by its drivers --- system/libraries/Driver.php | 4 ++-- system/libraries/Session/Session.php | 27 +++++++++++++++++++++- .../libraries/Session/drivers/Session_cookie.php | 10 -------- .../libraries/Session/drivers/Session_native.php | 11 ++++----- 4 files changed, 33 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 1d084c8e4..769d892dc 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -63,7 +63,7 @@ class CI_Driver_Library { * @return object Child class */ public function __get($child) - { + { // Try to load the driver return $this->load_driver($child); } @@ -284,4 +284,4 @@ class CI_Driver { } /* End of file Driver.php */ -/* Location: ./system/libraries/Driver.php */ +/* Location: ./system/libraries/Driver.php */ \ No newline at end of file diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php index e6f6050c0..978506062 100755 --- a/system/libraries/Session/Session.php +++ b/system/libraries/Session/Session.php @@ -69,13 +69,21 @@ class CI_Session extends CI_Driver_Library { * routines in its constructor, and manages flashdata aging. * * @param array Configuration parameters + * @return void */ public function __construct(array $params = array()) { + $CI =& get_instance(); + + // No sessions under CLI + if ($CI->input->is_cli_request()) + { + return; + } + log_message('debug', 'CI_Session Class Initialized'); // Get valid drivers list - $CI =& get_instance(); $this->valid_drivers = array( 'Session_native', 'Session_cookie' @@ -587,6 +595,23 @@ class CI_Session extends CI_Driver_Library { */ abstract class CI_Session_driver extends CI_Driver { + protected $CI; + + /** + * Constructor + * + * Gets the CI singleton, so that individual drivers + * don't have to do it separately. + * + * @return void + */ + public function __construct() + { + $this->CI =& get_instance(); + } + + // ------------------------------------------------------------------------ + /** * Decorate * diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 4f415cc0d..fb62c7ec4 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -157,13 +157,6 @@ class CI_Session_cookie extends CI_Session_driver { */ public $userdata = array(); - /** - * Reference to CodeIgniter instance - * - * @var object - */ - public $CI; - /** * Current time * @@ -197,9 +190,6 @@ class CI_Session_cookie extends CI_Session_driver { */ protected function initialize() { - // Set the super object to a local variable for use throughout the class - $this->CI =& get_instance(); - // Set all the session preferences, which can either be set // manually via the $params array or via the config file $prefs = array( diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index c97e15356..8d5e51546 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -46,7 +46,6 @@ class CI_Session_native extends CI_Session_driver { { // Get config parameters $config = array(); - $CI =& get_instance(); $prefs = array( 'sess_cookie_name', 'sess_expire_on_close', @@ -63,7 +62,7 @@ class CI_Session_native extends CI_Session_driver { { $config[$key] = isset($this->_parent->params[$key]) ? $this->_parent->params[$key] - : $CI->config->item($key); + : $this->CI->config->item($key); } // Set session name, if specified @@ -114,13 +113,13 @@ class CI_Session_native extends CI_Session_driver { $destroy = TRUE; } elseif ($config['sess_match_ip'] === TRUE && isset($_SESSION['ip_address']) - && $_SESSION['ip_address'] !== $CI->input->ip_address()) + && $_SESSION['ip_address'] !== $this->CI->input->ip_address()) { // IP doesn't match - destroy $destroy = TRUE; } elseif ($config['sess_match_useragent'] === TRUE && isset($_SESSION['user_agent']) - && $_SESSION['user_agent'] !== trim(substr($CI->input->user_agent(), 0, 50))) + && $_SESSION['user_agent'] !== trim(substr($this->CI->input->user_agent(), 0, 50))) { // Agent doesn't match - destroy $destroy = TRUE; @@ -149,13 +148,13 @@ class CI_Session_native extends CI_Session_driver { if ($config['sess_match_ip'] === TRUE && ! isset($_SESSION['ip_address'])) { // Store user IP address - $_SESSION['ip_address'] = $CI->input->ip_address(); + $_SESSION['ip_address'] = $this->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)); + $_SESSION['user_agent'] = trim(substr($this->CI->input->user_agent(), 0, 50)); } // Make session ID available -- cgit v1.2.3-24-g4f1b From e8bc5f4450381b4f978f274f3e93604301115b64 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 10 Oct 2012 11:13:59 +0300 Subject: Replace in _prep_quoted_printable() with the constant 76 --- system/libraries/Email.php | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 36ecc347d..1b457aee4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1112,14 +1112,6 @@ class CI_Email { return quoted_printable_encode($str); } - // Set the character limit - // Don't allow over 76, as that will make servers and MUAs barf - // all over quoted-printable data - if ($charlim === '' OR $charlim > 76) - { - $charlim = 76; - } - // Reduce multiple spaces & remove nulls $str = preg_replace(array('| +|', '/\x00+/'), array(' ', ''), $str); @@ -1162,7 +1154,7 @@ class CI_Email { // If we're at the character limit, add the line to the output, // reset our temp variable, and keep on chuggin' - if ((strlen($temp) + strlen($char)) >= $charlim) + if ((strlen($temp) + strlen($char)) >= 76) { $output .= $temp.$escape.$this->crlf; $temp = ''; -- cgit v1.2.3-24-g4f1b From 6c5f751b5ae66800e7ef3f70306a6bcbcdeeabf1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 10 Oct 2012 15:56:18 +0300 Subject: mbstring related changes --- system/core/Utf8.php | 37 ++++++++++++++++++------------------ system/libraries/Form_validation.php | 6 ------ 2 files changed, 19 insertions(+), 24 deletions(-) (limited to 'system') diff --git a/system/core/Utf8.php b/system/core/Utf8.php index 0a7ec501c..9e6a4eb1b 100644 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -49,30 +49,31 @@ class CI_Utf8 { { log_message('debug', 'Utf8 Class Initialized'); - global $CFG; + $charset = strtoupper(config_item('charset')); + + // set internal encoding for multibyte string functions if necessary + // and set a flag so we don't have to repeatedly use extension_loaded() + // or function_exists() + if (extension_loaded('mbstring')) + { + define('MB_ENABLED', TRUE); + mb_internal_encoding($charset); + } + else + { + define('MB_ENABLED', FALSE); + } + if ( - @preg_match('/./u', 'é') === 1 // PCRE must support UTF-8 - && function_exists('iconv') // iconv must be installed - && (bool) @ini_get('mbstring.func_overload') !== TRUE // Multibyte string function overloading cannot be enabled - && $CFG->item('charset') === 'UTF-8' // Application charset must be UTF-8 + @preg_match('/./u', 'é') === 1 // PCRE must support UTF-8 + && function_exists('iconv') // iconv must be installed + && MB_ENABLED === TRUE // mbstring must be enabled + && $charset === 'UTF-8' // Application charset must be UTF-8 ) { define('UTF8_ENABLED', TRUE); log_message('debug', 'UTF-8 Support Enabled'); - - // set internal encoding for multibyte string functions if necessary - // and set a flag so we don't have to repeatedly use extension_loaded() - // or function_exists() - if (extension_loaded('mbstring')) - { - define('MB_ENABLED', TRUE); - mb_internal_encoding('UTF-8'); - } - else - { - define('MB_ENABLED', FALSE); - } } else { diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index b490a34ca..fccc12afa 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -134,12 +134,6 @@ class CI_Form_validation { // Automatically load the form helper $this->CI->load->helper('form'); - // Set the character encoding in MB. - if (MB_ENABLED === TRUE) - { - mb_internal_encoding($this->CI->config->item('charset')); - } - log_message('debug', 'Form Validation Class Initialized'); } -- cgit v1.2.3-24-g4f1b From 9f44c21a3c90e984becaea3948ebafe90d89ac56 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 10 Oct 2012 16:07:17 +0300 Subject: Changelog entry for previous commit and change default charset for the Email library to whatever the config array says --- system/core/Utf8.php | 2 +- system/libraries/Email.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'system') diff --git a/system/core/Utf8.php b/system/core/Utf8.php index 9e6a4eb1b..1ff02981b 100644 --- a/system/core/Utf8.php +++ b/system/core/Utf8.php @@ -136,7 +136,7 @@ class CI_Utf8 { { return @iconv($encoding, 'UTF-8', $str); } - elseif (function_exists('mb_convert_encoding')) + elseif (MB_ENABLED === TRUE) { return @mb_convert_encoding($str, 'UTF-8', $encoding); } diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 1b457aee4..698cb7679 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -98,6 +98,8 @@ class CI_Email { */ public function __construct($config = array()) { + $this->charset = strtoupper(config_item('charset')); + if (count($config) > 0) { $this->initialize($config); -- cgit v1.2.3-24-g4f1b From c6f9a5da098ed9e27d88b7c271c4e1ba76fa79d6 Mon Sep 17 00:00:00 2001 From: lysenkobv Date: Wed, 10 Oct 2012 20:11:34 +0300 Subject: libraries/Encrypt.php decode improvement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit if base64 string is NO valid the result of decoded string is something like this "23Y�����������S�� �����i��!q" (base64_encode(base64_decode($string)) !== $string) check is this base64 string valid --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index 679609251..dbe16b096 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -165,7 +165,7 @@ class CI_Encrypt { */ public function decode($string, $key = '') { - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string)) + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) || base64_encode(base64_decode($string)) !== $string) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 9738668fd6b4078c7eb9df3372e5035791caaaf4 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 11 Oct 2012 10:24:51 +0300 Subject: Fix issue #1875 --- system/database/drivers/mssql/mssql_driver.php | 2 +- system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php | 2 +- system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 2 +- system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index a62ea94b3..a5ace02e6 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -465,7 +465,7 @@ class CI_DB_mssql_driver extends CI_DB { $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 2346e683e..7c4b008b2 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -232,7 +232,7 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index ee7c1d15a..fd1c4b214 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -266,7 +266,7 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index a6739d192..3ffbd4c18 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -460,7 +460,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { $orderby = 'ORDER BY '.implode(', ', $this->qb_orderby); // We have to strip the ORDER BY clause - $sql = trim(substr($sql, 0, strrpos($sql, 'ORDER BY '.$orderby))); + $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.$orderby.') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) -- cgit v1.2.3-24-g4f1b From a52c775d490fede2a0cb7f54f0dcc5010d7e0465 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 11 Oct 2012 10:54:02 +0300 Subject: Replace a few require() uses with require_once() (should fix issue #1872) --- system/core/CodeIgniter.php | 2 +- system/core/Common.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/core/CodeIgniter.php b/system/core/CodeIgniter.php index 8159b19f5..f3592eaf9 100644 --- a/system/core/CodeIgniter.php +++ b/system/core/CodeIgniter.php @@ -50,7 +50,7 @@ * Load the global functions * ------------------------------------------------------ */ - require(BASEPATH.'core/Common.php'); + require_once(BASEPATH.'core/Common.php'); /* * ------------------------------------------------------ diff --git a/system/core/Common.php b/system/core/Common.php index 981af4559..341402c6b 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -150,7 +150,7 @@ if ( ! function_exists('load_class')) if (class_exists($name) === FALSE) { - require($path.$directory.'/'.$class.'.php'); + require_once($path.$directory.'/'.$class.'.php'); } break; @@ -164,7 +164,7 @@ if ( ! function_exists('load_class')) if (class_exists($name) === FALSE) { - require(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'); + require_once(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'); } } -- cgit v1.2.3-24-g4f1b From c16b4f4164a4a26c48b823caf086a9777dc75beb Mon Sep 17 00:00:00 2001 From: Bogdan Lysenko Date: Thu, 11 Oct 2012 11:41:01 +0300 Subject: Update system/libraries/Encrypt.php --- system/libraries/Encrypt.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Encrypt.php b/system/libraries/Encrypt.php index dbe16b096..73ab8ca7d 100644 --- a/system/libraries/Encrypt.php +++ b/system/libraries/Encrypt.php @@ -165,7 +165,7 @@ class CI_Encrypt { */ public function decode($string, $key = '') { - if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) || base64_encode(base64_decode($string)) !== $string) + if (preg_match('/[^a-zA-Z0-9\/\+=]/', $string) OR base64_encode(base64_decode($string)) !== $string) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 26f0cf9cf94869f9aed94f2a7f5bd4ad9180079e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 11 Oct 2012 13:52:39 +0300 Subject: Add a fallback to imap_8bit() for CI_Email::_prep_quoted_printable() --- system/libraries/Email.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 698cb7679..fa1d5e9bf 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1109,9 +1109,16 @@ class CI_Email { // However, many developers choose to override that and violate // the RFC rules due to (apparently) a bug in MS Exchange, // which only works with "\n". - if ($this->crlf === "\r\n" && is_php('5.3')) + if ($this->crlf === "\r\n") { - return quoted_printable_encode($str); + if (is_php('5.3')) + { + return quoted_printable_encode($str); + } + elseif (function_exists('imap_8bit')) + { + return imap_8bit($str); + } } // Reduce multiple spaces & remove nulls -- cgit v1.2.3-24-g4f1b From f38564d739455f46eb38bcbfaa8e255d0a50defe Mon Sep 17 00:00:00 2001 From: Raul Baldner Junior Date: Thu, 11 Oct 2012 11:32:23 -0300 Subject: New form_validation rule: 'differs' Added new validation rule 'differs'. It checks if the value of a field differs from the value of another field. --- system/language/english/form_validation_lang.php | 1 + system/libraries/Form_validation.php | 13 +++++++++++++ 2 files changed, 14 insertions(+) (limited to 'system') diff --git a/system/language/english/form_validation_lang.php b/system/language/english/form_validation_lang.php index cf1b3b503..6ff0cc2f4 100644 --- a/system/language/english/form_validation_lang.php +++ b/system/language/english/form_validation_lang.php @@ -42,6 +42,7 @@ $lang['is_numeric'] = 'The %s field must contain only numeric characters.'; $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['differs'] = 'The %s field must differ from the %s field.'; $lang['is_unique'] = 'The %s field must contain a unique value.'; $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.'; diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index fccc12afa..6db5bb495 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -970,6 +970,19 @@ class CI_Form_validation { // -------------------------------------------------------------------- + /** + * Differs from another field + * + * @param string + * @param string field + * @return bool + */ + public function differs($str, $field) + { + return ! (isset($this->_field_data[$field]) && $this->_field_data[$field]['postdata'] === $str); + } + + // -------------------------------------------------------------------- /** * Is Unique * -- cgit v1.2.3-24-g4f1b From 9ae82faaad2f6b07a050d79129652b74483d1da0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 11 Oct 2012 20:58:45 +0300 Subject: [ci skip] Minor changes following PR #1871 --- system/libraries/Form_validation.php | 1 + 1 file changed, 1 insertion(+) (limited to 'system') diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php index 6db5bb495..91f46b6de 100644 --- a/system/libraries/Form_validation.php +++ b/system/libraries/Form_validation.php @@ -983,6 +983,7 @@ class CI_Form_validation { } // -------------------------------------------------------------------- + /** * Is Unique * -- cgit v1.2.3-24-g4f1b From 9d3aa1bc9f09c226ce0a55c285cb7fe808db5fa7 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 12:14:09 +0300 Subject: Fix _get_operator() for 'LIKE expr ESCAPE' --- system/database/DB_driver.php | 3 +-- system/database/DB_query_builder.php | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ea56d3819..02c64f9f1 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -1167,9 +1167,8 @@ abstract class CI_DB_driver { if (empty($_operators)) { $_les = ($this->_like_escape_str !== '') - ? preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))) + ? '\s+'.preg_quote(trim(sprintf($this->_like_escape_str, $this->_like_escape_chr))) : ''; - $_operators = array( '\s*(?:<|>|!)?=\s*', // =, <=, >=, != '\s*<>?\s*', // <, <> diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 139f467e6..9c6cb7e45 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2050,8 +2050,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { if (count($this->$qb_key) > 0) { - $sql = ($qb_key === 'qb_having') ? "\nHAVING " : "\nWHERE "; - for ($i = 0, $c = count($this->$qb_key); $i < $c; $i++) { if ($this->{$qb_key}[$i]['escape'] === FALSE) @@ -2081,7 +2079,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { .' '.trim($matches[4]).$matches[5].$matches[6]; } - return implode("\n", $this->$qb_key); + return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ") + .implode("\n", $this->$qb_key); } return ''; -- cgit v1.2.3-24-g4f1b From 13f5054a478ee52a9ef262216248337ef40d6677 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 12:31:02 +0300 Subject: Fix delete() with multiple tables and an erroneous variable --- system/database/DB_query_builder.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 9c6cb7e45..ab04e4db2 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -1832,10 +1832,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { foreach ($table as $single_table) { - $this->delete($single_table, $where, $limit, FALSE); + $this->delete($single_table, $where, $limit, $reset_data); } - - $this->_reset_write(); return; } else @@ -2109,7 +2107,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE) ? $this->qb_groupby[$i]['field'] - : $this->protect_identifiers($qb_groupby[$i]['field']); + : $this->protect_identifiers($this->qb_groupby[$i]['field']); } $sql .= implode(', ', $this->qb_groupby); -- cgit v1.2.3-24-g4f1b From 0bcf590db467e4aeb755e79daaccd38c83fe2439 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 13:03:29 +0300 Subject: Fix having(), group_by() --- system/database/DB_query_builder.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index ab04e4db2..ac8ff48a3 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -920,7 +920,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * @param bool * @return object */ - public function having($key, $value = '', $escape = NULL) + public function having($key, $value = NULL, $escape = NULL) { return $this->_wh('qb_having', $key, $value, 'AND ', $escape); } @@ -937,7 +937,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * @param bool * @return object */ - public function or_having($key, $value = '', $escape = NULL) + public function or_having($key, $value = NULL, $escape = NULL) { return $this->_wh('qb_having', $key, $value, 'OR ', $escape); } @@ -1812,7 +1812,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * @param mixed the where clause * @param mixed the limit clause * @param bool - * @return object + * @return mixed */ public function delete($table = '', $where = '', $limit = NULL, $reset_data = TRUE) { @@ -2101,8 +2101,6 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { if (count($this->qb_groupby) > 0) { - $sql = "\nGROUP BY "; - for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) { $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE) @@ -2110,7 +2108,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { : $this->protect_identifiers($this->qb_groupby[$i]['field']); } - $sql .= implode(', ', $this->qb_groupby); + return "\nGROUP BY ".implode(', ', $this->qb_groupby); } return ''; -- cgit v1.2.3-24-g4f1b From f2ec8b870e29e0bf346e7adf1968b0f7660669b6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 14:01:13 +0300 Subject: Fix where() with literal multiple conditions --- system/database/DB_query_builder.php | 43 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index ac8ff48a3..49592840b 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2056,25 +2056,36 @@ abstract class CI_DB_query_builder extends CI_DB_driver { continue; } - $op = preg_quote($this->_get_operator($this->{$qb_key}[$i]['condition'])); - if ( ! preg_match('/^(\s*(?:AND|OR)\s+)?(\(?)(.*)('.$op.')(.*(?{$qb_key}[$i]['condition'], $matches)) + // Split multiple conditions + $conditions = preg_split( + '/(\s*AND\s+|\s*OR\s+)/i', + $this->{$qb_key}[$i]['condition'], + -1, + PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY + ); + + for ($ci = 0, $cc = count($conditions); $ci < $cc; $ci++) { - $this->{$qb_key}[$i] = $this->{$qb_key}[$i]['condition']; - continue; + if (($op = $this->_get_operator($conditions[$ci])) === FALSE + OR ! preg_match('/^(\(?)(.*)('.preg_quote($op).')(.*(? '(test <= foo)', /* the whole thing */ + // 1 => '(', /* optional */ + // 2 => 'test', /* the field name */ + // 3 => ' <= ', /* $op */ + // 4 => 'foo', /* optional, if $op is e.g. 'IS NULL' */ + // 5 => ')' /* optional */ + // ); + empty($matches[4]) OR $matches[4] = ' '.$this->protect_identifiers(trim($matches[4])); + $conditions[$ci] = $matches[1].$this->protect_identifiers(trim($matches[2])) + .' '.trim($matches[3]).$matches[4].$matches[5]; } - // $matches = array( - // 0 => 'OR (test <= foo)', /* the whole thing */ - // 1 => 'OR ', /* optional */ - // 2 => '(', /* optional */ - // 3 => 'test', /* the field name */ - // 4 => ' <= ', /* $op */ - // 5 => 'foo', /* optional, if $op is e.g. 'IS NULL' */ - // 6 => ')' /* optional */ - // ); - empty($matches[5]) OR $matches[5] = ' '.$this->protect_identifiers(trim($matches[5])); - $this->{$qb_key}[$i] = $matches[1].$matches[2].$this->protect_identifiers(trim($matches[3])) - .' '.trim($matches[4]).$matches[5].$matches[6]; + $this->{$qb_key}[$i] = implode('', $conditions); } return ($qb_key === 'qb_having' ? "\nHAVING " : "\nWHERE ") -- cgit v1.2.3-24-g4f1b From cc02db959db576f256eb62887d326493e44d45af Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 14:30:10 +0300 Subject: Fix where_in() --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 49592840b..54fb50f6a 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -599,7 +599,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $where_in = array(); foreach ($values as $value) { - $wherein[] = $this->escape($value); + $where_in[] = $this->escape($value); } $prefix = (count($this->qb_where) === 0) ? $this->_group_get_type('') : $this->_group_get_type($type); -- cgit v1.2.3-24-g4f1b From fc043b3d00a94c473a03cd6927e83e3518e391c0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 14:46:14 +0300 Subject: Fix order_by() --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 54fb50f6a..936d114bd 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2148,7 +2148,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { if ($this->qb_orderby[$i]['escape'] !== FALSE) { - $this->qb_orderby[$i]['field'] = $this->protect_identifiers($field); + $this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']); } $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; -- cgit v1.2.3-24-g4f1b From a23e10fd2369cc85c4b942c5de6a8cf05a5b2b67 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 14:54:25 +0300 Subject: Really fix order_by() --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 936d114bd..4f89d78d0 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2154,7 +2154,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; } - $sql .= implode(', ', $this->qb_orderby); + return "\nORDER BY ".implode(', ', $this->qb_orderby); } return ''; -- cgit v1.2.3-24-g4f1b From 2f8bf9b4c5ee9bc183e17fd36b54be12a1bf75bb Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 20:37:52 +0300 Subject: Set MySQL client compression to FALSE by default (problems reported with it), fix some typos, add encrypted database connections support and fix SQLSRV CharacterSet setting --- system/database/DB_driver.php | 2 +- system/database/drivers/mysql/mysql_driver.php | 26 +++++------- system/database/drivers/mysqli/mysqli_driver.php | 49 +++++++--------------- .../drivers/pdo/subdrivers/pdo_mysql_driver.php | 7 ++++ .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 4 +- system/database/drivers/sqlsrv/sqlsrv_driver.php | 9 ++-- system/helpers/date_helper.php | 2 +- 7 files changed, 41 insertions(+), 58 deletions(-) (limited to 'system') diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index ea2a53eb2..fef388bbf 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -51,7 +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 $encrypt = FALSE; public $swap_pre = ''; public $port = ''; public $pconnect = FALSE; diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 7262591ee..336db971d 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -41,6 +41,7 @@ class CI_DB_mysql_driver extends CI_DB { public $dbdriver = 'mysql'; + public $compress = FALSE; // The character used for escaping protected $_escape_char = '`'; @@ -75,18 +76,20 @@ class CI_DB_mysql_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool * @return resource */ - public function db_connect() + public function db_connect($persistent = FALSE) { - if ($this->compress === TRUE) - { - return @mysql_connect($this->hostname, $this->username, $this->password, TRUE, MYSQL_CLIENT_COMPRESS); - } - else + $connect_func = ($persistent === TRUE) ? 'mysql_pconnect' : 'mysql_connect'; + $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS; + + if ($this->encrypt === TRUE) { - return @mysql_connect($this->hostname, $this->username, $this->password, TRUE); + $client_flags = $client_flags | MYSQL_CLIENT_SSL; } + + return @$connect_func($this->hostname, $this->username, $this->password, TRUE, $client_flags); } // -------------------------------------------------------------------- @@ -98,14 +101,7 @@ class CI_DB_mysql_driver extends CI_DB { */ public function db_pconnect() { - 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); - } + return $this->db_connect(TRUE); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index b5a1e26ed..f77176c16 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -41,6 +41,7 @@ class CI_DB_mysqli_driver extends CI_DB { public $dbdriver = 'mysqli'; + public $compress = FALSE; // The character used for escaping protected $_escape_char = '`'; @@ -57,24 +58,21 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool * @return object + * @todo SSL support */ - public function db_connect() + public function db_connect($persistent = FALSE) { - // Use MySQL client compression? - if ($this->compress === TRUE) - { - $port = empty($this->port) ? NULL : $this->port; - - $mysqli = new mysqli(); - @$mysqli->real_connect($this->hostname, $this->username, $this->password, $this->database, $port, NULL, MYSQLI_CLIENT_COMPRESS); - - return $mysqli; - } - - 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); + // Persistent connection support was added in PHP 5.3.0 + $hostname = ($persistent === TRUE && is_php('5.3')) + ? 'p:'.$this->hostname : $this->hostname; + $port = empty($this->port) ? NULL : $this->port; + $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0; + $mysqli = new mysqli(); + + return @$mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, NULL, $client_flags) + ? $mysqli : FALSE; } // -------------------------------------------------------------------- @@ -86,26 +84,7 @@ class CI_DB_mysqli_driver extends CI_DB { */ public function db_pconnect() { - // Persistent connection support was added in PHP 5.3.0 - if ( ! is_php('5.3')) - { - 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); + return $this->db_connect(TRUE); } // -------------------------------------------------------------------- diff --git a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php index 42446889a..a54311712 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_mysql_driver.php @@ -41,6 +41,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { public $subdriver = 'mysql'; + public $compress = FALSE; protected $_escape_char = '`'; @@ -79,6 +80,7 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { * * @param bool * @return object + * @todo SSL support */ public function db_connect($persistent = FALSE) { @@ -93,6 +95,11 @@ class CI_DB_pdo_mysql_driver extends CI_DB_pdo_driver { .(empty($this->dbcollat) ? '' : ' COLLATE '.$this->dbcollat); } + if ($this->compress === TRUE) + { + $this->options[PDO::MYSQL_ATTR_COMPRESS] = TRUE; + } + return parent::db_connect($persistent); } diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index fd1c4b214..3154fddb9 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -78,9 +78,9 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { $this->dsn .= ';ConnectionPooling='.$this->ConnectionPooling; } - if (isset($this->Encrypt)) + if ($this->encrypt === TRUE) { - $this->dsn .= ';Encrypt='.$this->Encrypt; + $this->dsn .= ';Encrypt=1'; } if (isset($this->TraceOn)) diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 3ffbd4c18..be321ff11 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -57,15 +57,16 @@ class CI_DB_sqlsrv_driver extends CI_DB { */ public function db_connect($pooling = FALSE) { - // Check for a UTF-8 charset being passed as CI's default 'utf8'. - $character_set = (0 === strcasecmp('utf8', $this->char_set)) ? 'UTF-8' : $this->char_set; + $charset = in_array(strtolower($this->char_set), array('utf-8', 'utf8'), TRUE) + ? 'UTF-8' : SQLSRV_ENC_CHAR; $connection = array( 'UID' => empty($this->username) ? '' : $this->username, 'PWD' => empty($this->password) ? '' : $this->password, 'Database' => $this->database, - 'ConnectionPooling' => $pooling ? 1 : 0, - 'CharacterSet' => $character_set, + 'ConnectionPooling' => ($pooling === TRUE) ? 1 : 0, + 'CharacterSet' => $charset, + 'Encrypt' => ($this->encrypt === TRUE) ? 1 : 0, 'ReturnDatesAsStrings' => 1 ); diff --git a/system/helpers/date_helper.php b/system/helpers/date_helper.php index 955d74542..51b2b76db 100644 --- a/system/helpers/date_helper.php +++ b/system/helpers/date_helper.php @@ -669,7 +669,7 @@ if ( ! function_exists('date_range')) * @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 parameter + * @param mixed is_unix Specifies whether the second parameter * is a UNIX timestamp or a day interval * - TRUE or 'unix' for a timestamp * - FALSE or 'days' for an interval -- cgit v1.2.3-24-g4f1b From 98ebf4351f8aad58504cd7318ddd94faf0dec482 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 12 Oct 2012 20:44:03 +0300 Subject: Fix mysql's db_connect() --- system/database/drivers/mysql/mysql_driver.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index 336db971d..99bf55942 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -81,7 +81,6 @@ class CI_DB_mysql_driver extends CI_DB { */ public function db_connect($persistent = FALSE) { - $connect_func = ($persistent === TRUE) ? 'mysql_pconnect' : 'mysql_connect'; $client_flags = ($this->compress === FALSE) ? 0 : MYSQL_CLIENT_COMPRESS; if ($this->encrypt === TRUE) @@ -89,7 +88,9 @@ class CI_DB_mysql_driver extends CI_DB { $client_flags = $client_flags | MYSQL_CLIENT_SSL; } - return @$connect_func($this->hostname, $this->username, $this->password, TRUE, $client_flags); + return ($persistent === TRUE) + ? @mysql_pconnect($this->hostname, $this->username, $this->password, $client_flags) + : @mysql_connect($this->hostname, $this->username, $this->password, TRUE, $client_flags); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 82d2cf17e77d0ca5ffdcaafb72ca2d3dc82dc142 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 13 Oct 2012 12:38:42 +0300 Subject: Fix CI_Input::ip_address() subnet detection --- system/core/Input.php | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'system') diff --git a/system/core/Input.php b/system/core/Input.php index 82482f2aa..ec935d531 100644 --- a/system/core/Input.php +++ b/system/core/Input.php @@ -390,31 +390,32 @@ class CI_Input { } // Convert the REMOTE_ADDR IP address to binary, if needed - if ( ! isset($ip, $convert_func)) + if ( ! isset($ip, $sprintf)) { if ($separator === ':') { // Make sure we're have the "full" IPv6 format - $ip = str_replace('::', str_repeat(':', 9 - substr_count($this->ip_address, ':')), $this->ip_address); - $convert_func = is_php('5.3') - ? function ($value) - { - return str_pad(base_convert($value, 16, 2), 16, '0', STR_PAD_LEFT); - } - : create_function('$value', 'return str_pad(base_convert($value, 16, 2), 16, "0", STR_PAD_LEFT);'); + $ip = explode(':', + str_replace('::', + str_repeat(':', 9 - substr_count($this->ip_address, ':')), + $this->ip_address + ) + ); + + for ($i = 0; $i < 8; $i++) + { + $ip[$i] = intval($ip[$i], 16); + } + + $sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b'; } else { - $ip = $this->ip_address; - $convert_func = is_php('5.3') - ? function ($value) - { - return str_pad(decbin($value), 8, '0', STR_PAD_LEFT); - } - : create_function('$value', 'return str_pad(decbin($value), 8, "0", STR_PAD_LEFT);'); + $ip = explode('.', $this->ip_address); + $sprintf = '%08b%08b%08b%08b'; } - $ip = implode(array_map($convert_func, explode($separator, $ip))); + $ip = vsprintf($sprintf, $ip); } // Split the netmask length off the network address @@ -423,12 +424,19 @@ class CI_Input { // Again, an IPv6 address is most likely in a compressed form if ($separator === ':') { - $netaddr = str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr); + $netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr)); + for ($i = 0; $i < 8; $i++) + { + $netaddr[$i] = intval($netaddr[$i], 16); + } + } + else + { + $netaddr = explode('.', $netaddr); } - // Convert to a binary form and finally compare - $netaddr = implode(array_map($convert_func, explode($separator, $netaddr))); - if (strncmp($ip, $netaddr, $masklen) === 0) + // Convert to binary and finally compare + if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0) { $this->ip_address = $spoof; break; -- cgit v1.2.3-24-g4f1b From 37c85d73c4428bd19fafbba33992649fc29946d5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Sat, 13 Oct 2012 17:08:45 +0300 Subject: Apparently not all PHP builds consider mysqli::__construct() with no parameters to be the same as mysqli_init() --- system/database/drivers/mysqli/mysqli_driver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index f77176c16..dc72ecc5f 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -69,7 +69,7 @@ class CI_DB_mysqli_driver extends CI_DB { ? 'p:'.$this->hostname : $this->hostname; $port = empty($this->port) ? NULL : $this->port; $client_flags = ($this->compress === TRUE) ? MYSQLI_CLIENT_COMPRESS : 0; - $mysqli = new mysqli(); + $mysqli = mysqli_init(); return @$mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, NULL, $client_flags) ? $mysqli : FALSE; -- cgit v1.2.3-24-g4f1b From 02117680c8a3a4c7da2b10e25fc6c29fd5fa9bd2 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 15 Oct 2012 11:12:37 +0300 Subject: Partially fix #1702 --- system/libraries/Session/drivers/Session_cookie.php | 2 +- system/libraries/Session/drivers/Session_native.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index fb62c7ec4..5bb1f7aa6 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -405,7 +405,7 @@ class CI_Session_cookie extends CI_Session_driver { } // Is the session current? - if (($session['last_activity'] + $this->sess_expiration) < $this->now) + if (($session['last_activity'] + $this->sess_expiration) < $this->now OR $session['last_activity'] > $this->now) { $this->sess_destroy(); return FALSE; diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 8d5e51546..6529d4c36 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -107,7 +107,7 @@ class CI_Session_native extends CI_Session_driver { // Check session expiration, ip, and agent $now = time(); $destroy = FALSE; - if (isset($_SESSION['last_activity']) && ($_SESSION['last_activity'] + $expire) < $now) + if (isset($_SESSION['last_activity']) && (($_SESSION['last_activity'] + $expire) < $now OR $_SESSION['last_activity'] > $now)) { // Expired - destroy $destroy = TRUE; -- cgit v1.2.3-24-g4f1b From c7719284833f211984474623832b96707173e02d Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 15 Oct 2012 14:12:22 +0300 Subject: Remove CI_Email::_get_ip() --- system/libraries/Email.php | 41 ----------------------------------------- 1 file changed, 41 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index fa1d5e9bf..08057f2f7 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -1753,47 +1753,6 @@ class CI_Email { // -------------------------------------------------------------------- - /** - * Get IP - * - * @return string - */ - protected function _get_ip() - { - if ($this->_IP !== FALSE) - { - return $this->_IP; - } - - $cip = ( ! empty($_SERVER['HTTP_CLIENT_IP'])) ? $_SERVER['HTTP_CLIENT_IP'] : FALSE; - $rip = ( ! empty($_SERVER['REMOTE_ADDR'])) ? $_SERVER['REMOTE_ADDR'] : FALSE; - if ($cip) $this->_IP = $cip; - elseif ($rip) $this->_IP = $rip; - else - { - $fip = ( ! empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : FALSE; - if ($fip) - { - $this->_IP = $fip; - } - } - - if (strpos($this->_IP, ',') !== FALSE) - { - $x = explode(',', $this->_IP); - $this->_IP = end($x); - } - - if ( ! preg_match('/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/', $this->_IP)) - { - $this->_IP = '0.0.0.0'; - } - - return $this->_IP; - } - - // -------------------------------------------------------------------- - /** * Get Debug Message * -- cgit v1.2.3-24-g4f1b From 19cd88799f27bef8d502250c86eddcd72789bdb3 Mon Sep 17 00:00:00 2001 From: GDmac Date: Tue, 16 Oct 2012 14:19:57 +0200 Subject: Session Native, respect cookie settings Respect config settings for cookie_secure and cookie_httponly Signed-off-by: GDmac --- .../libraries/Session/drivers/Session_native.php | 24 +++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index 6529d4c36..d7b9e8410 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -55,7 +55,9 @@ class CI_Session_native extends CI_Session_driver { 'sess_time_to_update', 'cookie_prefix', 'cookie_path', - 'cookie_domain' + 'cookie_domain', + 'cookie_secure', + 'cookie_httponly' ); foreach ($prefs as $key) @@ -82,6 +84,9 @@ class CI_Session_native extends CI_Session_driver { $expire = 7200; $path = '/'; $domain = ''; + $secure = FALSE; + $http_only = FALSE; + if ($config['sess_expiration'] !== FALSE) { // Default to 2 years if expiration is "0" @@ -99,7 +104,20 @@ class CI_Session_native extends CI_Session_driver { // Use specified domain $domain = $config['cookie_domain']; } - session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain); + + if ($config['cookie_secure']) + { + // Send over SSL / HTTPS only? + $secure = $config['cookie_secure']; + } + + if ($config['cookie_httponly']) + { + // only available to HTTP(S)? + $http_only = $config['http_only']; + } + + session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain, $secure, $http_only); // Start session session_start(); @@ -189,7 +207,7 @@ class CI_Session_native extends CI_Session_driver { { // Clear session cookie $params = session_get_cookie_params(); - setcookie($name, '', time() - 42000, $params['path'], $params['domain']); + setcookie($name, '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']); unset($_COOKIE[$name]); } session_destroy(); -- cgit v1.2.3-24-g4f1b From 28616da32bcf72f37c0e61e304a1799b90ceec3f Mon Sep 17 00:00:00 2001 From: GDmac Date: Tue, 16 Oct 2012 15:01:14 +0200 Subject: Native PHP Session, don't regenerate session_id during ajax Signed-off-by: GDmac --- system/libraries/Session/drivers/Session_native.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index d7b9e8410..fb3b638a0 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -155,8 +155,12 @@ class CI_Session_native extends CI_Session_driver { 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); + // Changing the session ID amidst a series of AJAX calls causes problems + if( ! $this->CI->input->is_ajax_request()) + { + // Regenerate ID, but don't destroy session + $this->sess_regenerate(FALSE); + } } // Set activity time -- cgit v1.2.3-24-g4f1b From f69f0e8f02815d44e218b013c8da92cebabbdcb1 Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Tue, 16 Oct 2012 11:54:49 -0400 Subject: Updating the cookie driver to use HMAC authentication on all cookie data. Signed-off-by: Pascal Kriete --- .../libraries/Session/drivers/Session_cookie.php | 45 +++++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 5bb1f7aa6..b44c8330e 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -372,27 +372,31 @@ class CI_Session_cookie extends CI_Session_driver { return FALSE; } + $len = strlen($session) - 40; + + if ($len < 0) + { + log_message('debug', 'The session cookie was not signed.'); + return FALSE; + } + + // Check cookie authentication + $hmac = substr($session, $len); + $session = substr($session, 0, $len); + + if ($hmac !== hash_hmac('sha1', $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; + } + // 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 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)) - { - 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); @@ -658,10 +662,13 @@ class CI_Session_cookie extends CI_Session_driver { // Serialize the userdata for the cookie $cookie_data = $this->_serialize($cookie_data); - $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.md5($cookie_data.$this->encryption_key); + if ($this->sess_encrypt_cookie === TRUE) + { + $this->CI->encrypt->encode($cookie_data); + } + + // Require message authentication + $cookie_data .= hash_hmac('sha1', $cookie_data, $this->encryption_key); $expire = ($this->sess_expire_on_close === TRUE) ? 0 : $this->sess_expiration + time(); -- cgit v1.2.3-24-g4f1b From ff5ffdf7fa3b458510a95788ac3baa6fba3178cc Mon Sep 17 00:00:00 2001 From: GDmac Date: Tue, 16 Oct 2012 19:22:12 +0200 Subject: session native, fix cookie settings Signed-off-by: GDmac --- system/libraries/Session/drivers/Session_native.php | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php index fb3b638a0..da744f39b 100755 --- a/system/libraries/Session/drivers/Session_native.php +++ b/system/libraries/Session/drivers/Session_native.php @@ -84,8 +84,8 @@ class CI_Session_native extends CI_Session_driver { $expire = 7200; $path = '/'; $domain = ''; - $secure = FALSE; - $http_only = FALSE; + $secure = (bool) $config['cookie_secure']; + $http_only = (bool) $config['cookie_httponly']; if ($config['sess_expiration'] !== FALSE) { @@ -105,18 +105,6 @@ class CI_Session_native extends CI_Session_driver { $domain = $config['cookie_domain']; } - if ($config['cookie_secure']) - { - // Send over SSL / HTTPS only? - $secure = $config['cookie_secure']; - } - - if ($config['cookie_httponly']) - { - // only available to HTTP(S)? - $http_only = $config['http_only']; - } - session_set_cookie_params($config['sess_expire_on_close'] ? 0 : $expire, $path, $domain, $secure, $http_only); // Start session -- cgit v1.2.3-24-g4f1b From 8a7078b65dc387c8d74f963b80a7559bd094458a Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 17 Oct 2012 10:52:49 +0300 Subject: Fix issue #1897 --- system/libraries/Email.php | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 08057f2f7..5b17edf9b 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -292,16 +292,7 @@ class CI_Email { $this->set_header('To', implode(', ', $to)); } - switch ($this->_get_protocol()) - { - case 'smtp': - $this->_recipients = $to; - break; - case 'sendmail': - case 'mail': - $this->_recipients = implode(', ', $to); - break; - } + $this->_recipients = $to; return $this; } @@ -1408,6 +1399,11 @@ class CI_Email { */ protected function _send_with_mail() { + if (is_array($this->_recipients)) + { + $this->_recipients = implode(', ', $this->_recipients); + } + if ($this->_safe_mode === TRUE) { return mail($this->_recipients, $this->_subject, $this->_finalbody, $this->_header_str); -- cgit v1.2.3-24-g4f1b From 28dc2023d32e1d997e2b90052f1960f98a255d2c Mon Sep 17 00:00:00 2001 From: Pascal Kriete Date: Wed, 17 Oct 2012 11:27:29 -0400 Subject: Changing session error logging verbiage to be a little less unsettling. Signed-off-by: Pascal Kriete --- system/libraries/Session/drivers/Session_cookie.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index b44c8330e..51d94da4e 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -386,7 +386,7 @@ class CI_Session_cookie extends CI_Session_driver { if ($hmac !== hash_hmac('sha1', $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->sess_destroy(); return FALSE; } -- cgit v1.2.3-24-g4f1b From 00ea2a9a3a6451d106ed3f083716f59e84d5f656 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 18 Oct 2012 14:59:29 +0300 Subject: Remove {unwrap}{/unwrap} markers when quoted_printable_encode() or imap_8bit() is used --- system/libraries/Email.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 5b17edf9b..bc9d62eb4 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -754,7 +754,7 @@ class CI_Email { { if ($this->alt_message !== '') { - return $this->word_wrap($this->alt_message, '76'); + return $this->word_wrap($this->alt_message, 76); } $body = preg_match('/\(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body; @@ -777,12 +777,12 @@ class CI_Email { * @param int * @return string */ - public function word_wrap($str, $charlim = '') + public function word_wrap($str, $charlim = NULL) { - // Se the character limit - if ($charlim === '') + // Set the character limit, if not already present + if (empty($charlim)) { - $charlim = ($this->wrapchars === '') ? 76 : $this->wrapchars; + $charlim = empty($this->wrapchars) ? 76 : $this->wrapchars; } // Reduce multiple spaces @@ -1096,6 +1096,10 @@ class CI_Email { */ protected function _prep_quoted_printable($str) { + // We are intentionally wrapping so mail servers will encode characters + // properly and MUAs will behave, so {unwrap} must go! + $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str); + // RFC 2045 specifies CRLF as "\r\n". // However, many developers choose to override that and violate // the RFC rules due to (apparently) a bug in MS Exchange, @@ -1121,10 +1125,6 @@ class CI_Email { $str = str_replace(array("\r\n", "\r"), "\n", $str); } - // We are intentionally wrapping so mail servers will encode characters - // properly and MUAs will behave, so {unwrap} must go! - $str = str_replace(array('{unwrap}', '{/unwrap}'), '', $str); - $escape = '='; $output = ''; -- cgit v1.2.3-24-g4f1b From cf264e0d165647f30efdef1b2d944849bebf4c72 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Thu, 18 Oct 2012 16:14:51 +0300 Subject: Fix Session cookies not being encrypted on creation and sess_destroy() not actually deleting cookies --- system/libraries/Session/drivers/Session_cookie.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php index 51d94da4e..8617aec2d 100755 --- a/system/libraries/Session/drivers/Session_cookie.php +++ b/system/libraries/Session/drivers/Session_cookie.php @@ -308,7 +308,7 @@ class CI_Session_cookie extends CI_Session_driver { } // Kill the cookie - $this->_setcookie($this->sess_cookie_name, addslashes(serialize(array())), ($this->now - 31500000), + $this->_setcookie($this->sess_cookie_name, '', ($this->now - 31500000), $this->cookie_path, $this->cookie_domain, 0); // Kill session data @@ -664,7 +664,7 @@ class CI_Session_cookie extends CI_Session_driver { if ($this->sess_encrypt_cookie === TRUE) { - $this->CI->encrypt->encode($cookie_data); + $cookie_data = $this->CI->encrypt->encode($cookie_data); } // Require message authentication -- cgit v1.2.3-24-g4f1b From 929e1241879c94bff85203d2e00623284d72dc87 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 19 Oct 2012 10:09:28 +0300 Subject: Manually apply an improved version of PR #1797 (auto_link() URL helper) --- system/helpers/url_helper.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'system') diff --git a/system/helpers/url_helper.php b/system/helpers/url_helper.php index b1f5eccf1..de5bdec31 100644 --- a/system/helpers/url_helper.php +++ b/system/helpers/url_helper.php @@ -388,40 +388,43 @@ if ( ! function_exists('auto_link')) for ($i = 0, $c = count($matches[0]); $i < $c; $i++) { - if (preg_match('|\.$|', $matches[6][$i])) + if (preg_match('/(\.|\,)$/i', $matches[6][$i], $m)) { - $period = '.'; + $punct = $m[1]; $matches[6][$i] = substr($matches[6][$i], 0, -1); } else { - $period = ''; + $punct = ''; } $str = str_replace($matches[0][$i], $matches[1][$i].'http' .$matches[4][$i].'://'.$matches[5][$i] - .$matches[6][$i].''.$period, + .$matches[6][$i].''.$punct, $str); } } - if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]*)/i', $str, $matches)) + if ($type !== 'url' && preg_match_all('/([a-zA-Z0-9_\.\-\+]+)@([a-zA-Z0-9\-]+)\.([a-zA-Z0-9\-\.]+)/i', $str, $matches)) { for ($i = 0, $c = count($matches); $i < $c; $i++) { - if (preg_match('|\.$|', $matches[3][$i])) + if (preg_match('/(\.|\,)$/i', $matches[3][$i], $m)) { - $period = '.'; + $punct = $m[1]; $matches[3][$i] = substr($matches[3][$i], 0, -1); } else { - $period = ''; + $punct = ''; } - $str = str_replace($matches[0][$i], safe_mailto($matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]).$period, $str); + if (filter_var(($m = $matches[1][$i].'@'.$matches[2][$i].'.'.$matches[3][$i]), FILTER_VALIDATE_EMAIL) !== FALSE) + { + $str = str_replace($matches[0][$i], safe_mailto($m).$punct, $str); + } } } -- cgit v1.2.3-24-g4f1b From 925dd9030db7a5a47d8a79f94b35827b14b9b685 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 19 Oct 2012 11:06:31 +0300 Subject: Fix issue #1409 --- system/libraries/Email.php | 110 ++++++++++++++++++++++++--------------------- 1 file changed, 59 insertions(+), 51 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index bc9d62eb4..795db2043 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -98,7 +98,7 @@ class CI_Email { */ public function __construct($config = array()) { - $this->charset = strtoupper(config_item('charset')); + $this->charset = config_item('charset'); if (count($config) > 0) { @@ -110,6 +110,8 @@ class CI_Email { $this->_safe_mode = (bool) @ini_get('safe_mode'); } + $this->charset = strtoupper($this->charset); + log_message('debug', 'Email Class Initialized'); } @@ -186,11 +188,11 @@ class CI_Email { /** * Set FROM * - * @param string - * @param string + * @param string From + * @param string Return-Path * @return object */ - public function from($from, $name = '', $return_path = '') + public function from($from, $name = '', $return_path = NULL) { if (preg_match('/\<(.*)\>/', $from, $match)) { @@ -217,16 +219,13 @@ class CI_Email { } else { - $name = $this->_prep_q_encoding($name, TRUE); + $name = $this->_prep_q_encoding($name); } } $this->set_header('From', $name.' <'.$from.'>'); - if( ! $return_path) - { - $return_path = $from; - } + isset($return_path) OR $return_path = $from; $this->set_header('Return-Path', '<'.$return_path.'>'); return $this; @@ -1177,66 +1176,75 @@ class CI_Email { /** * Prep Q Encoding * - * Performs "Q Encoding" on a string for use in email headers. It's related - * but not identical to quoted-printable, so it has its own method + * Performs "Q Encoding" on a string for use in email headers. + * It's related but not identical to quoted-printable, so it has its + * own method. * * @param string - * @param bool set to TRUE for processing From: headers * @return string */ - protected function _prep_q_encoding($str, $from = FALSE) + protected function _prep_q_encoding($str) { - $str = str_replace(array("\r", "\n"), array('', ''), $str); - - // Line length must not exceed 76 characters, so we adjust for - // a space, 7 extra characters =??Q??=, and the charset that we will add to each line - $limit = 75 - 7 - strlen($this->charset); + $str = str_replace(array("\r", "\n"), '', $str); - // these special characters must be converted too - $convert = array('_', '=', '?'); - - if ($from === TRUE) + if ($this->charset === 'UTF-8') { - $convert[] = ','; - $convert[] = ';'; + if (MB_ENABLED === TRUE) + { + return mb_encode_mimeheader($str, $this->charset, 'Q', $this->crlf); + } + elseif (extension_loaded('iconv')) + { + $output = @iconv_mime_encode('', $str, + array( + 'scheme' => 'Q', + 'line-length' => 76, + 'input-charset' => $this->charset, + 'output-charset' => $this->charset, + 'line-break-chars' => $this->crlf + ) + ); + + // There are reports that iconv_mime_encode() might fail and return FALSE + if ($output !== FALSE) + { + // iconv_mime_encode() will always put a header field name. + // We've passed it an empty one, but it still prepends our + // encoded string with ': ', so we need to strip it. + return substr($output, 2); + } + + $chars = iconv_strlen($str, 'UTF-8'); + } } - $output = ''; - $temp = ''; + // We might already have this set for UTF-8 + isset($chars) OR $chars = strlen($str); - for ($i = 0, $length = strlen($str); $i < $length; $i++) + $output = '=?'.$this->charset.'?Q?'; + for ($i = 0, $length = strlen($output), $iconv = extension_loaded('iconv'); $i < $chars; $i++) { - // Grab the next character - $char = $str[$i]; - $ascii = ord($char); - - // convert ALL non-printable ASCII characters and our specials - if ($ascii < 32 OR $ascii > 126 OR in_array($char, $convert)) - { - $char = '='.dechex($ascii); - } + $chr = ($this->charset === 'UTF-8' && $iconv === TRUE) + ? '='.implode('=', str_split(strtoupper(bin2hex(iconv_substr($str, $i, 1, $this->charset))), 2)) + : '='.strtoupper(bin2hex($str[$i])); - // handle regular spaces a bit more compactly than =20 - if ($ascii === 32) + // RFC 2045 sets a limit of 76 characters per line. + // We'll append ?= to the end of each line though. + if ($length + ($l = strlen($chr)) > 74) { - $char = '_'; + $output .= '?='.$this->crlf // EOL + .' =?'.$this->charset.'?Q?'.$chr; // New line + $length = 6 + strlen($this->charset) + $l; // Reset the length for the new line } - - // If we're at the character limit, add the line to the output, - // reset our temp variable, and keep on chuggin' - if ((strlen($temp) + strlen($char)) >= $limit) + else { - $output .= $temp.$this->crlf; - $temp = ''; + $output .= $chr; + $length += $l; } - - // Add the character to our temporary line - $temp .= $char; } - // wrap each line with the shebang, charset, and transfer encoding - // the preceding space on successive lines is required for header "folding" - return trim(preg_replace('/^(.*?)(\r*)$/m', ' =?'.$this->charset.'?Q?$1?=$2', $output.$temp)); + // End the header + return $output.'?='; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 8df1ae2d7e0fd441f7a1fc481c76c5c1edfadf23 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Fri, 19 Oct 2012 11:20:54 +0300 Subject: Fix another mailing issue (based on #1281) --- system/libraries/Email.php | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'system') diff --git a/system/libraries/Email.php b/system/libraries/Email.php index 795db2043..c1130e915 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -742,8 +742,8 @@ class CI_Email { /** * Build alternative plain text message * - * This public function provides the raw message for use - * in plain-text headers of HTML-formatted emails. + * Provides the raw message for use in plain-text headers of + * HTML-formatted emails. * If the user hasn't specified his own alternative message * it creates one by stripping the HTML * @@ -751,9 +751,11 @@ class CI_Email { */ protected function _get_alt_message() { - if ($this->alt_message !== '') + if ( ! empty($this->alt_message)) { - return $this->word_wrap($this->alt_message, 76); + return ($this->wordwrap) + ? $this->word_wrap($this->alt_message, 76) + : $this->alt_message; } $body = preg_match('/\(.*)\<\/body\>/si', $this->_body, $match) ? $match[1] : $this->_body; @@ -764,7 +766,9 @@ class CI_Email { $body = str_replace(str_repeat("\n", $i), "\n\n", $body); } - return $this->word_wrap($body, 76); + return ($this->wordwrap) + ? $this->word_wrap($body, 76) + : $body; } // -------------------------------------------------------------------- @@ -773,7 +777,7 @@ class CI_Email { * Word Wrap * * @param string - * @param int + * @param int line-length limit * @return string */ public function word_wrap($str, $charlim = NULL) -- cgit v1.2.3-24-g4f1b From e66d6243aaf13053631641973a0beff656a94510 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Oct 2012 16:39:12 +0300 Subject: Fix issues #1476, #1909 --- system/libraries/Pagination.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/libraries/Pagination.php b/system/libraries/Pagination.php index e1e729bb0..36b57b332 100644 --- a/system/libraries/Pagination.php +++ b/system/libraries/Pagination.php @@ -157,7 +157,7 @@ class CI_Pagination { // See if we are using a prefix or suffix on links if ($this->prefix !== '' OR $this->suffix !== '') { - $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->segment($this->uri_segment)); + $this->cur_page = (int) str_replace(array($this->prefix, $this->suffix), '', $CI->uri->rsegment($this->uri_segment)); } if ($CI->config->item('enable_query_strings') === TRUE OR $this->page_query_string === TRUE) @@ -169,7 +169,7 @@ class CI_Pagination { } elseif ( ! $this->cur_page && $CI->uri->segment($this->uri_segment) !== $base_page) { - $this->cur_page = (int) $CI->uri->segment($this->uri_segment); + $this->cur_page = (int) $CI->uri->rsegment($this->uri_segment); } // Set current page to 1 if it's not valid or if using page numbers instead of offset -- cgit v1.2.3-24-g4f1b From 3fb026713013b60845c4cfe633a8a59a30b9c7dd Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Oct 2012 16:48:01 +0300 Subject: Add is_https() as a common function --- system/core/Common.php | 18 ++++++++++++++++++ system/core/Config.php | 2 +- system/core/Security.php | 2 +- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'system') diff --git a/system/core/Common.php b/system/core/Common.php index 341402c6b..2dd31d3e9 100644 --- a/system/core/Common.php +++ b/system/core/Common.php @@ -330,6 +330,24 @@ if ( ! function_exists('get_mimes')) // ------------------------------------------------------------------------ +if ( ! function_exists('is_https')) +{ + /** + * Is HTTPS? + * + * Determines if the application is accessed via an encrypted + * (HTTPS) connection. + * + * @return bool + */ + function is_https() + { + return ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off'); + } +} + +// ------------------------------------------------------------------------ + if ( ! function_exists('show_error')) { /** diff --git a/system/core/Config.php b/system/core/Config.php index 8e4f998ef..e78128c76 100644 --- a/system/core/Config.php +++ b/system/core/Config.php @@ -75,7 +75,7 @@ class CI_Config { { if (isset($_SERVER['HTTP_HOST'])) { - $base_url = ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') ? 'https' : 'http'; + $base_url = is_https() ? 'https' : 'http'; $base_url .= '://'.$_SERVER['HTTP_HOST'] .str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); } diff --git a/system/core/Security.php b/system/core/Security.php index b22d2cf19..2fbc5b34c 100644 --- a/system/core/Security.php +++ b/system/core/Security.php @@ -198,7 +198,7 @@ class CI_Security { $expire = time() + $this->_csrf_expire; $secure_cookie = (bool) config_item('cookie_secure'); - if ($secure_cookie && (empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) === 'off')) + if ($secure_cookie && ! is_https()) { return FALSE; } -- cgit v1.2.3-24-g4f1b From 082aa4025ff5764cf10d429903bf48f66a65ce9e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Oct 2012 19:41:55 +0300 Subject: Fix where() & having() escaping/prefixing literal values containing a period --- system/database/DB_query_builder.php | 44 ++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 4f89d78d0..1ab165835 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2067,7 +2067,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { for ($ci = 0, $cc = count($conditions); $ci < $cc; $ci++) { if (($op = $this->_get_operator($conditions[$ci])) === FALSE - OR ! preg_match('/^(\(?)(.*)('.preg_quote($op).')(.*(? 'foo', /* optional, if $op is e.g. 'IS NULL' */ // 5 => ')' /* optional */ // ); - empty($matches[4]) OR $matches[4] = ' '.$this->protect_identifiers(trim($matches[4])); + + if ( ! empty($matches[4])) + { + $this->_is_literal($matches[4]) OR $matches[4] = $this->protect_identifiers(trim($matches[4])); + $matches[4] = ' '.$matches[4]; + } + $conditions[$ci] = $matches[1].$this->protect_identifiers(trim($matches[2])) .' '.trim($matches[3]).$matches[4].$matches[5]; } @@ -2114,7 +2120,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { { for ($i = 0, $c = count($this->qb_groupby); $i < $c; $i++) { - $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE) + $this->qb_groupby[$i] = ($this->qb_groupby[$i]['escape'] === FALSE OR $this->_is_literal($this->qb_groupby[$i]['field'])) ? $this->qb_groupby[$i]['field'] : $this->protect_identifiers($this->qb_groupby[$i]['field']); } @@ -2146,7 +2152,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) { - if ($this->qb_orderby[$i]['escape'] !== FALSE) + if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field'])) { $this->qb_orderby[$i]['field'] = $this->protect_identifiers($this->qb_orderby[$i]['field']); } @@ -2323,6 +2329,36 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- + /** + * Is literal + * + * Determines if a string represents a literal value or a field name + * + * @param string + * @return bool + */ + protected function _is_literal($str) + { + $str = trim($str); + + if (empty($str)) + { + return TRUE; + } + + static $_str; + + if (empty($_str)) + { + $_str = ($this->_escape_char !== '"') + ? array('"', "'") : array("'"); + } + + return (ctype_digit($str) OR in_array($str[0], $_str, TRUE)); + } + + // -------------------------------------------------------------------- + /** * Reset Query Builder values. * -- cgit v1.2.3-24-g4f1b From 9f6bdc0b1b9f56997527652a0e1d09a9b233d32e Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Mon, 22 Oct 2012 23:31:10 +0300 Subject: Fix #1913 --- system/database/DB_result.php | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'system') diff --git a/system/database/DB_result.php b/system/database/DB_result.php index d44df6c02..e747044d8 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -251,27 +251,24 @@ class CI_DB_result { /** * Query result. Acts as a wrapper function for the following functions. * - * @param string + * @param mixed * @param string can be "object" or "array" - * @return mixed either a result object or array + * @return mixed */ public function row($n = 0, $type = 'object') { if ( ! is_numeric($n)) { // We cache the row data for subsequent uses - if ( ! is_array($this->row_data)) - { - $this->row_data = $this->row_array(0); - } + is_array($this->row_data) OR $this->row_data = $this->row_array(0); - // array_key_exists() instead of isset() to allow for MySQL NULL values - if (array_key_exists($n, $this->row_data)) + // array_key_exists() instead of isset() to allow for NULL values + if (empty($this->row_data) OR ! array_key_exists($n, $this->row_data)) { - return $this->row_data[$n]; + return NULL; } - // reset the $n variable if the result was not achieved - $n = 0; + + return $this->row_data[$n]; } if ($type === 'object') return $this->row_object($n); -- cgit v1.2.3-24-g4f1b From f5f898f8f30968fb36413a14de2dc6a4599b79a6 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 02:13:29 +0300 Subject: Fix issue #779 --- system/core/URI.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'system') diff --git a/system/core/URI.php b/system/core/URI.php index 6a8b1a5ac..15e6a5599 100644 --- a/system/core/URI.php +++ b/system/core/URI.php @@ -165,11 +165,8 @@ class CI_URI { */ protected function _set_uri_string($str) { - // Filter out control characters - $str = remove_invisible_characters($str, FALSE); - - // If the URI contains only a slash we'll kill it - $this->uri_string = ($str === '/') ? '' : $str; + // Filter out control characters and trim slashes + $this->uri_string = trim(remove_invisible_characters($str, FALSE), '/'); } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b From 256a18c50f0c042ae80d931ab3bd54b09f0fafa0 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 12:18:32 +0300 Subject: Fix issues #134, #1911 --- system/database/DB_cache.php | 16 +++++----------- system/helpers/file_helper.php | 2 +- 2 files changed, 6 insertions(+), 12 deletions(-) (limited to 'system') diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index ba9110382..bdd91867a 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -43,6 +43,8 @@ class CI_DB_Cache { $this->CI =& get_instance(); $this->db =& $db; $this->CI->load->helper('file'); + + $this->check_path(); } // -------------------------------------------------------------------- @@ -66,7 +68,9 @@ class CI_DB_Cache { } // Add a trailing slash to the path if needed - $path = preg_replace('/(.+?)\/*$/', '\\1/', $path); + $path = realpath($path) + ? rtrim(realpath($path), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR + : rtrim($path, '/').'/'; if ( ! is_dir($path) OR ! is_really_writable($path)) { @@ -90,11 +94,6 @@ class CI_DB_Cache { */ public function read($sql) { - if ( ! $this->check_path()) - { - return $this->db->cache_off(); - } - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $filepath = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'.md5($sql); @@ -116,11 +115,6 @@ class CI_DB_Cache { */ public function write($sql, $object) { - if ( ! $this->check_path()) - { - return $this->db->cache_off(); - } - $segment_one = ($this->CI->uri->segment(1) == FALSE) ? 'default' : $this->CI->uri->segment(1); $segment_two = ($this->CI->uri->segment(2) == FALSE) ? 'index' : $this->CI->uri->segment(2); $dir_path = $this->db->cachedir.$segment_one.'+'.$segment_two.'/'; diff --git a/system/helpers/file_helper.php b/system/helpers/file_helper.php index e68bb7f7a..441345b05 100644 --- a/system/helpers/file_helper.php +++ b/system/helpers/file_helper.php @@ -109,7 +109,7 @@ if ( ! function_exists('delete_files')) function delete_files($path, $del_dir = FALSE, $level = 0, $htdocs = FALSE) { // Trim the trailing slash - $path = rtrim($path, DIRECTORY_SEPARATOR); + $path = rtrim($path, '/\\'); if ( ! $current_dir = @opendir($path)) { -- cgit v1.2.3-24-g4f1b From a53ea846b045e57ebd94463e463965124eba7142 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 12:44:09 +0300 Subject: Alter _compile_order_by() to re-fix MSSQL, SQLSRV limit() --- system/database/DB_query_builder.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 1ab165835..0eb5a9e45 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -2146,10 +2146,8 @@ abstract class CI_DB_query_builder extends CI_DB_driver { */ protected function _compile_order_by() { - if (count($this->qb_orderby) > 0) + if (is_array($this->qb_orderby) && count($this->qb_orderby) > 0) { - $sql = "\nORDER BY "; - for ($i = 0, $c = count($this->qb_orderby); $i < $c; $i++) { if ($this->qb_orderby[$i]['escape'] !== FALSE && ! $this->_is_literal($this->qb_orderby[$i]['field'])) @@ -2160,7 +2158,11 @@ abstract class CI_DB_query_builder extends CI_DB_driver { $this->qb_orderby[$i] = $this->qb_orderby[$i]['field'].$this->qb_orderby[$i]['direction']; } - return "\nORDER BY ".implode(', ', $this->qb_orderby); + return $this->qb_orderby = "\nORDER BY ".implode(', ', $this->qb_orderby); + } + elseif (is_string($this->qb_orderby)) + { + return $this->qb_orderby; } return ''; -- cgit v1.2.3-24-g4f1b From 4451454e190bdee2f865bd9d9e0fde0a6dff8b3c Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Tue, 23 Oct 2012 15:35:09 +0300 Subject: Fix issue #1917 --- system/database/drivers/mssql/mssql_driver.php | 23 ++++++++++++++++++-- .../drivers/pdo/subdrivers/pdo_dblib_driver.php | 25 +++++++++++++++++++--- .../drivers/pdo/subdrivers/pdo_sqlsrv_driver.php | 25 +++++++++++++++++++--- system/database/drivers/sqlsrv/sqlsrv_driver.php | 23 ++++++++++++++++++-- 4 files changed, 86 insertions(+), 10 deletions(-) (limited to 'system') diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 4369bbefb..3d6cffd29 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -438,9 +438,28 @@ class CI_DB_mssql_driver extends CI_DB { // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); - return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) - ."\n) ".$this->escape_identifiers('CI_subquery') + ."\n\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } diff --git a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php index 782bb53c0..785b2795c 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php @@ -211,9 +211,28 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); - return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) - ."\n) ".$this->escape_identifiers('CI_subquery') + ."\n\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } @@ -223,4 +242,4 @@ class CI_DB_pdo_dblib_driver extends CI_DB_pdo_driver { } /* End of file pdo_dblib_driver.php */ -/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php */ +/* Location: ./system/database/drivers/pdo/subdrivers/pdo_dblib_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php index 64be355f8..33bd7bea5 100644 --- a/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php +++ b/system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php @@ -245,9 +245,28 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); - return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) - ."\n) ".$this->escape_identifiers('CI_subquery') + ."\n\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } @@ -257,4 +276,4 @@ class CI_DB_pdo_sqlsrv_driver extends CI_DB_pdo_driver { } /* End of file pdo_sqlsrv_driver.php */ -/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php */ +/* Location: ./system/database/drivers/pdo/subdrivers/pdo_sqlsrv_driver.php */ \ No newline at end of file diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 31a0d9d10..8f615223c 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -440,9 +440,28 @@ class CI_DB_sqlsrv_driver extends CI_DB { // We have to strip the ORDER BY clause $sql = trim(substr($sql, 0, strrpos($sql, $orderby))); - return 'SELECT '.(count($this->qb_select) === 0 ? '*' : implode(', ', $this->qb_select))." FROM (\n" + // Get the fields to select from our subquery, so that we can avoid CI_rownum appearing in the actual results + if (count($this->qb_select) === 0) + { + $select = '*'; // Inevitable + } + else + { + // Use only field names and their aliases, everything else is out of our scope. + $select = array(); + $field_regexp = ($this->_quoted_identifier) + ? '("[^\"]+")' : '(\[[^\]]+\])'; + for ($i = 0, $c = count($this->qb_select); $i < $c; $i++) + { + $select[] = preg_match('/(?:\s|\.)'.$field_regexp.'$/i', $this->qb_select[$i], $m) + ? $m[1] : $this->qb_select[$i]; + } + $select = implode(', ', $select); + } + + return 'SELECT '.$select." FROM (\n\n" .preg_replace('/^(SELECT( DISTINCT)?)/i', '\\1 ROW_NUMBER() OVER('.trim($orderby).') AS '.$this->escape_identifiers('CI_rownum').', ', $sql) - ."\n) ".$this->escape_identifiers('CI_subquery') + ."\n\n) ".$this->escape_identifiers('CI_subquery') ."\nWHERE ".$this->escape_identifiers('CI_rownum').' BETWEEN '.($this->qb_offset + 1).' AND '.$limit; } -- cgit v1.2.3-24-g4f1b From 93dd2f2896979258fe52eaf937a3c0855b4bbcf1 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 10:09:18 +0300 Subject: Fix issue #1925 (order_by() with = FALSE) --- system/database/DB_query_builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'system') diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index 0eb5a9e45..a6e6e595f 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -975,7 +975,7 @@ abstract class CI_DB_query_builder extends CI_DB_driver { if ($escape === FALSE) { - $qb_orderby[] = array(array('field' => $orderby, 'direction' => $direction, $escape => FALSE)); + $qb_orderby[] = array('field' => $orderby, 'direction' => $direction, 'escape' => FALSE); } else { -- cgit v1.2.3-24-g4f1b From 5fd3ae8d33a4f5d3159b86683b9a670e973a63f5 Mon Sep 17 00:00:00 2001 From: Andrey Andreev Date: Wed, 24 Oct 2012 14:55:35 +0300 Subject: [ci skip] style and phpdoc-related changes (rel #1295) --- system/core/Controller.php | 2 + system/core/Loader.php | 4 +- system/core/Output.php | 3 +- system/database/DB_cache.php | 15 +++- system/database/DB_driver.php | 15 ++-- system/database/DB_forge.php | 15 ++-- system/database/DB_query_builder.php | 68 ++++++++++-------- system/database/DB_result.php | 26 ++++--- system/database/DB_utility.php | 6 ++ system/database/drivers/cubrid/cubrid_driver.php | 7 ++ system/database/drivers/cubrid/cubrid_result.php | 1 + system/database/drivers/ibase/ibase_driver.php | 1 + system/database/drivers/mssql/mssql_driver.php | 5 +- system/database/drivers/mssql/mssql_result.php | 1 + system/database/drivers/mysql/mysql_driver.php | 1 + system/database/drivers/mysql/mysql_result.php | 1 + system/database/drivers/mysqli/mysqli_driver.php | 1 + system/database/drivers/mysqli/mysqli_result.php | 1 + system/database/drivers/oci8/oci8_driver.php | 6 ++ system/database/drivers/odbc/odbc_driver.php | 9 +++ system/database/drivers/pdo/pdo_driver.php | 3 +- system/database/drivers/postgre/postgre_driver.php | 1 + system/database/drivers/postgre/postgre_forge.php | 14 ++-- system/database/drivers/postgre/postgre_result.php | 1 + system/database/drivers/sqlite/sqlite_driver.php | 1 + system/database/drivers/sqlite/sqlite_result.php | 1 + system/database/drivers/sqlite3/sqlite3_driver.php | 6 +- system/database/drivers/sqlite3/sqlite3_result.php | 1 + system/database/drivers/sqlsrv/sqlsrv_driver.php | 2 + system/helpers/text_helper.php | 22 +++--- system/helpers/typography_helper.php | 5 +- system/libraries/Driver.php | 3 +- system/libraries/Email.php | 20 ++++-- system/libraries/Ftp.php | 7 ++ system/libraries/Javascript.php | 32 ++++++--- system/libraries/Trackback.php | 5 ++ system/libraries/Unit_test.php | 34 ++++++--- system/libraries/Upload.php | 4 +- system/libraries/Xmlrpc.php | 14 ++-- system/libraries/javascript/Jquery.php | 83 +++++++++++++--------- 40 files changed, 303 insertions(+), 144 deletions(-) (limited to 'system') diff --git a/system/core/Controller.php b/system/core/Controller.php index 491414807..9196958ae 100644 --- a/system/core/Controller.php +++ b/system/core/Controller.php @@ -42,6 +42,7 @@ class CI_Controller { /** * Reference to the global CI instance * + * @static * @var object */ private static $instance; @@ -71,6 +72,7 @@ class CI_Controller { /** * Return the CI object * + * @static * @return object */ public static function &get_instance() diff --git a/system/core/Loader.php b/system/core/Loader.php index 75e93608a..5de2e5dde 100644 --- a/system/core/Loader.php +++ b/system/core/Loader.php @@ -689,7 +689,7 @@ class CI_Loader { */ public function get_package_paths($include_base = FALSE) { - return $include_base === TRUE ? $this->_ci_library_paths : $this->_ci_model_paths; + return ($include_base === TRUE) ? $this->_ci_library_paths : $this->_ci_model_paths; } // -------------------------------------------------------------------- @@ -1005,7 +1005,7 @@ class CI_Loader { $path = strtolower($class).'/'.$class; return $this->_ci_load_class($path, $params, $object_name); } - else if (ucfirst($subdir) != $subdir) + elseif (ucfirst($subdir) != $subdir) { // Lowercase subdir failed - retry capitalized $path = ucfirst($subdir).$class; diff --git a/system/core/Output.php b/system/core/Output.php index 052367ed6..aa0e05dc4 100644 --- a/system/core/Output.php +++ b/system/core/Output.php @@ -204,7 +204,8 @@ class CI_Output { /** * Set Content Type Header * - * @param string extension of the file we're outputting + * @param string $mime_type extension of the file we're outputting + * @param string $charset = NULL * @return void */ public function set_content_type($mime_type, $charset = NULL) diff --git a/system/database/DB_cache.php b/system/database/DB_cache.php index bdd91867a..671147b3d 100644 --- a/system/database/DB_cache.php +++ b/system/database/DB_cache.php @@ -37,6 +37,12 @@ class CI_DB_Cache { public $CI; public $db; // allows passing of db object so that multiple database connections and returned db objects can be supported + /** + * Constructor + * + * @param &$db + * @return void + */ public function __construct(&$db) { // Assign the main CI object to $this->CI and load the file helper since we use it a lot @@ -90,6 +96,7 @@ class CI_DB_Cache { * The URI being requested will become the name of the cache sub-folder. * An MD5 hash of the SQL statement will become the cache file name * + * @param string $sql * @return string */ public function read($sql) @@ -111,6 +118,8 @@ class CI_DB_Cache { /** * Write a query to a cache file * + * @param string $sql + * @param object $object * @return bool */ public function write($sql, $object) @@ -144,7 +153,9 @@ class CI_DB_Cache { /** * Delete cache files within a particular directory * - * @return bool + * @param string $segment_one = '' + * @param string $segment_two = '' + * @return void */ public function delete($segment_one = '', $segment_two = '') { @@ -167,7 +178,7 @@ class CI_DB_Cache { /** * Delete all existing cache files * - * @return bool + * @return void */ public function delete_all() { diff --git a/system/database/DB_driver.php b/system/database/DB_driver.php index b7b19d207..7f1434fc1 100644 --- a/system/database/DB_driver.php +++ b/system/database/DB_driver.php @@ -310,8 +310,9 @@ abstract class CI_DB_driver { * FALSE upon failure, and if the $db_debug variable is set to TRUE * will raise an error. * - * @param string An SQL query string - * @param array An array of binding data + * @param string $sql + * @param array $binds = FALSE An array of binding data + * @param bool $return_object = NULL * @return mixed */ public function query($sql, $binds = FALSE, $return_object = NULL) @@ -514,6 +515,7 @@ abstract class CI_DB_driver { * If strict mode is disabled, each group is treated autonomously, meaning * a failure of one group will not affect any others * + * @param bool $mode = TRUE * @return void */ public function trans_strict($mode = TRUE) @@ -526,6 +528,7 @@ abstract class CI_DB_driver { /** * Start Transaction * + * @param bool $test_mode = FALSE * @return void */ public function trans_start($test_mode = FALSE) @@ -810,6 +813,7 @@ abstract class CI_DB_driver { /** * Returns an array of table names * + * @param string $constrain_by_prefix = FALSE * @return array */ public function list_tables($constrain_by_prefix = FALSE) @@ -864,6 +868,7 @@ abstract class CI_DB_driver { /** * Determine if a particular table exists * + * @param string $table_name * @return bool */ public function table_exists($table_name) @@ -1193,8 +1198,8 @@ abstract class CI_DB_driver { /** * Enables a native PHP function to be run, using a platform agnostic wrapper. * - * @param string the function name - * @param mixed any parameters needed by the function + * @param string $function the function name + * @param mixed $param,... optional parameters needed by the function * @return mixed */ public function call_function($function) @@ -1258,6 +1263,8 @@ abstract class CI_DB_driver { /** * Delete the cache files associated with a particular URI * + * @param string $segment_one = '' + * @param string $segment_two = '' * @return bool */ public function cache_delete($segment_one = '', $segment_two = '') diff --git a/system/database/DB_forge.php b/system/database/DB_forge.php index 91f9d560c..119d78d38 100644 --- a/system/database/DB_forge.php +++ b/system/database/DB_forge.php @@ -37,7 +37,7 @@ abstract class CI_DB_forge { public $fields = array(); public $keys = array(); public $primary_keys = array(); - public $db_char_set = ''; + public $db_char_set = ''; // Platform specific SQL strings protected $_create_database = 'CREATE DATABASE %s'; @@ -45,6 +45,11 @@ abstract class CI_DB_forge { protected $_drop_table = 'DROP TABLE IF EXISTS %s'; protected $_rename_table = 'ALTER TABLE %s RENAME TO %s'; + /** + * Constructor + * + * @return void + */ public function __construct() { // Assign the main database object to $this->db @@ -206,7 +211,8 @@ abstract class CI_DB_forge { /** * Create Table * - * @param string the table name + * @param string $table = '' + * @param bool $if_not_exists = FALSE * @return bool */ public function create_table($table = '', $if_not_exists = FALSE) @@ -378,9 +384,8 @@ abstract class CI_DB_forge { /** * Column Modify * - * @param string the table name - * @param string the column name - * @param string the column definition + * @param string $table = '' + * @param string $field = array() column definition * @return bool */ public function modify_column($table = '', $field = array()) diff --git a/system/database/DB_query_builder.php b/system/database/DB_query_builder.php index a6e6e595f..5fc3d1866 100644 --- a/system/database/DB_query_builder.php +++ b/system/database/DB_query_builder.php @@ -182,15 +182,17 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Processing Function for the four functions above: + * Processing Function for the following functions: * * select_max() * select_min() * select_avg() * select_sum() * - * @param string the field - * @param string an alias + * + * @param string $select = '' field name + * @param string $alias = '' + * @param string $type = 'MAX' * @return object */ protected function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') @@ -504,11 +506,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Where_in * - * Generates a WHERE field IN ('item', 'item') SQL query joined with + * Generates a WHERE field IN('item', 'item') SQL query joined with * AND if appropriate * - * @param string The field to search - * @param array The values searched on + * @param string $key = NULL The field to search + * @param array $values = NULL The values searched on + * @param bool $escape = NULL * @return object */ public function where_in($key = NULL, $values = NULL, $escape = NULL) @@ -519,13 +522,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Where_in_or + * Or_where_in * - * Generates a WHERE field IN ('item', 'item') SQL query joined with + * Generates a WHERE field IN('item', 'item') SQL query joined with * OR if appropriate * - * @param string The field to search - * @param array The values searched on + * @param string $key = NULL The field to search + * @param array $values = NULL The values searched on + * @param bool $escape = NULL * @return object */ public function or_where_in($key = NULL, $values = NULL, $escape = NULL) @@ -538,11 +542,12 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Where_not_in * - * Generates a WHERE field NOT IN ('item', 'item') SQL query joined + * Generates a WHERE field NOT IN('item', 'item') SQL query joined * with AND if appropriate * - * @param string The field to search - * @param array The values searched on + * @param string $key = NULL The field to search + * @param array $values = NULL The values searched on + * @param bool $escape = NULL * @return object */ public function where_not_in($key = NULL, $values = NULL, $escape = NULL) @@ -553,13 +558,14 @@ abstract class CI_DB_query_builder extends CI_DB_driver { // -------------------------------------------------------------------- /** - * Where_not_in_or + * Or_where_not_in * - * Generates a WHERE field NOT IN ('item', 'item') SQL query joined + * Generates a WHERE field NOT IN('item', 'item') SQL query joined * with OR if appropriate * - * @param string The field to search - * @param array The values searched on + * @param string $key = NULL The field to search + * @param array $values = NULL The values searched on + * @param bool $escape = NULL * @return object */ public function or_where_not_in($key = NULL, $values = NULL, $escape = NULL) @@ -572,12 +578,13 @@ abstract class CI_DB_query_builder extends CI_DB_driver { /** * Where_in * - * Called by where_in, where_in_or, where_not_in, where_not_in_or + * Called by where_in(), or_where_in(), where_not_in(), or_where_not_in() * - * @param string The field to search - * @param array The values searched on - * @param bool If the statement would be IN or NOT IN - * @param string + * @param string $key = NULL The field to search + * @param array $values = NULL The values searched on + * @param bool $not = FALSE If the statement would be IN or NOT IN + * @param string $type = 'AND ' + * @param bool $escape = NULL * @return object */ protected function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ', $escape = NULL) @@ -1174,9 +1181,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * * Allows the where clause, limit and offset to be added directly * - * @param string the where clause - * @param string the limit clause - * @param string the offset clause + * @param string $table = '' + * @param string $where = NULL + * @param int $limit = NULL + * @param int $offset = NULL * @return object */ public function get_where($table = '', $where = NULL, $limit = NULL, $offset = NULL) @@ -1535,9 +1543,10 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * * Compiles an update string and runs the query * - * @param string the table to retrieve the results from - * @param array an associative array of update values - * @param mixed the where clause + * @param string $table = '' + * @param array $set = NULL an associative array of update values + * @param mixed $where = NULL + * @param int $limit = NULL * @return object */ public function update($table = '', $set = NULL, $where = NULL, $limit = NULL) @@ -1967,8 +1976,9 @@ abstract class CI_DB_query_builder extends CI_DB_driver { * Compile the SELECT statement * * Generates a query string based on which functions were used. - * Should not be called directly. The get() function calls it. + * Should not be called directly. * + * @param bool $select_override = FALSE * @return string */ protected function _compile_select($select_override = FALSE) diff --git a/system/database/DB_result.php b/system/database/DB_result.php index e747044d8..76093f918 100644 --- a/system/database/DB_result.php +++ b/system/database/DB_result.php @@ -251,8 +251,8 @@ class CI_DB_result { /** * Query result. Acts as a wrapper function for the following functions. * - * @param mixed - * @param string can be "object" or "array" + * @param mixed $n = 0 + * @param string $type = 'object' 'object' or 'array' * @return mixed */ public function row($n = 0, $type = 'object') @@ -281,6 +281,8 @@ class CI_DB_result { /** * Assigns an item into a particular column slot * + * @param mixed $key + * @param mixed $value * @return void */ public function set_row($key, $value = NULL) @@ -311,6 +313,8 @@ class CI_DB_result { /** * Returns a single result row - custom object version * + * @param int $n + * @param string $type * @return object */ public function custom_row_object($n, $type) @@ -335,6 +339,7 @@ class CI_DB_result { /** * Returns a single result row - object version * + * @param int $n = 0 * @return object */ public function row_object($n = 0) @@ -358,6 +363,7 @@ class CI_DB_result { /** * Returns a single result row - array version * + * @param int $n = 0 * @return array */ public function row_array($n = 0) @@ -381,7 +387,8 @@ class CI_DB_result { /** * Returns the "first" row * - * @return object + * @param string $type = 'object' + * @return mixed */ public function first_row($type = 'object') { @@ -394,7 +401,8 @@ class CI_DB_result { /** * Returns the "last" row * - * @return object + * @param string $type = 'object' + * @return mixed */ public function last_row($type = 'object') { @@ -407,7 +415,8 @@ class CI_DB_result { /** * Returns the "next" row * - * @return object + * @param string $type = 'object' + * @return mixed */ public function next_row($type = 'object') { @@ -430,7 +439,8 @@ class CI_DB_result { /** * Returns the "previous" row * - * @return object + * @param string $type = 'object' + * @return mixed */ public function previous_row($type = 'object') { @@ -452,8 +462,8 @@ class CI_DB_result { /** * Returns an unbuffered row and move pointer to next row * - * @param string 'array', 'object' or a custom class name - * @return mixed either a result object or array + * @param string $type = 'object' 'array', 'object' or a custom class name + * @return mixed */ public function unbuffered_row($type = 'object') { diff --git a/system/database/DB_utility.php b/system/database/DB_utility.php index 6a3b40779..8078e2bf6 100644 --- a/system/database/DB_utility.php +++ b/system/database/DB_utility.php @@ -41,6 +41,11 @@ abstract class CI_DB_utility extends CI_DB_forge { protected $_optimize_table = FALSE; protected $_repair_table = FALSE; + /** + * Constructor + * + * @return void + */ public function __construct() { // Assign the main database object to $this->db @@ -275,6 +280,7 @@ abstract class CI_DB_utility extends CI_DB_forge { /** * Database Backup * + * @param array $params = array() * @return void */ public function backup($params = array()) diff --git a/system/database/drivers/cubrid/cubrid_driver.php b/system/database/drivers/cubrid/cubrid_driver.php index 7f8f297bb..8e77d8396 100644 --- a/system/database/drivers/cubrid/cubrid_driver.php +++ b/system/database/drivers/cubrid/cubrid_driver.php @@ -50,6 +50,12 @@ class CI_DB_cubrid_driver extends CI_DB { // CUBRID-specific properties public $auto_commit = TRUE; + /** + * Constructor + * + * @param array $params + * @return void + */ public function __construct($params) { parent::__construct($params); @@ -180,6 +186,7 @@ class CI_DB_cubrid_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/cubrid/cubrid_result.php b/system/database/drivers/cubrid/cubrid_result.php index 4a06a2d39..360c50dc2 100644 --- a/system/database/drivers/cubrid/cubrid_result.php +++ b/system/database/drivers/cubrid/cubrid_result.php @@ -132,6 +132,7 @@ class CI_DB_cubrid_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param int $n = 0 * @return bool */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/ibase/ibase_driver.php b/system/database/drivers/ibase/ibase_driver.php index 96d6f6526..c3be519bf 100644 --- a/system/database/drivers/ibase/ibase_driver.php +++ b/system/database/drivers/ibase/ibase_driver.php @@ -116,6 +116,7 @@ class CI_DB_ibase_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/mssql/mssql_driver.php b/system/database/drivers/mssql/mssql_driver.php index 3d6cffd29..2063dad90 100644 --- a/system/database/drivers/mssql/mssql_driver.php +++ b/system/database/drivers/mssql/mssql_driver.php @@ -50,12 +50,12 @@ class CI_DB_mssql_driver extends CI_DB { // MSSQL-specific properties protected $_quoted_identifier = TRUE; - /* + /** * Constructor * * Appends the port number to the hostname, if needed. * - * @param array + * @param array $params * @return void */ public function __construct($params) @@ -152,6 +152,7 @@ class CI_DB_mssql_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/mssql/mssql_result.php b/system/database/drivers/mssql/mssql_result.php index aeede3f4b..84d2814f1 100644 --- a/system/database/drivers/mssql/mssql_result.php +++ b/system/database/drivers/mssql/mssql_result.php @@ -133,6 +133,7 @@ class CI_DB_mssql_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param int $n = 0 * @return bool */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/mysql/mysql_driver.php b/system/database/drivers/mysql/mysql_driver.php index ce9f73011..f82e775e6 100644 --- a/system/database/drivers/mysql/mysql_driver.php +++ b/system/database/drivers/mysql/mysql_driver.php @@ -214,6 +214,7 @@ class CI_DB_mysql_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/mysql/mysql_result.php b/system/database/drivers/mysql/mysql_result.php index 7fbb65496..b3f669e40 100644 --- a/system/database/drivers/mysql/mysql_result.php +++ b/system/database/drivers/mysql/mysql_result.php @@ -146,6 +146,7 @@ class CI_DB_mysql_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param int $n = 0 * @return bool */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/mysqli/mysqli_driver.php b/system/database/drivers/mysqli/mysqli_driver.php index 91ab13a3c..6c4f87513 100644 --- a/system/database/drivers/mysqli/mysqli_driver.php +++ b/system/database/drivers/mysqli/mysqli_driver.php @@ -196,6 +196,7 @@ class CI_DB_mysqli_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/mysqli/mysqli_result.php b/system/database/drivers/mysqli/mysqli_result.php index c1ec4da76..f036302bb 100644 --- a/system/database/drivers/mysqli/mysqli_result.php +++ b/system/database/drivers/mysqli/mysqli_result.php @@ -132,6 +132,7 @@ class CI_DB_mysqli_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param int $n = 0 * @return bool */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/oci8/oci8_driver.php b/system/database/drivers/oci8/oci8_driver.php index 8e4f4ef9d..81d73d073 100644 --- a/system/database/drivers/oci8/oci8_driver.php +++ b/system/database/drivers/oci8/oci8_driver.php @@ -75,6 +75,12 @@ class CI_DB_oci8_driver extends CI_DB { // throw off num_fields later public $limit_used; + /** + * Constructor + * + * @param array $params + * @return void + */ public function __construct($params) { parent::__construct($params); diff --git a/system/database/drivers/odbc/odbc_driver.php b/system/database/drivers/odbc/odbc_driver.php index 741b7419f..063a04b98 100644 --- a/system/database/drivers/odbc/odbc_driver.php +++ b/system/database/drivers/odbc/odbc_driver.php @@ -49,6 +49,12 @@ class CI_DB_odbc_driver extends CI_DB { protected $_random_keyword; + /** + * Constructor + * + * @param array $params + * @return void + */ public function __construct($params) { parent::__construct($params); @@ -62,6 +68,8 @@ class CI_DB_odbc_driver extends CI_DB { } } + // -------------------------------------------------------------------- + /** * Non-persistent database connection * @@ -102,6 +110,7 @@ class CI_DB_odbc_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/pdo/pdo_driver.php b/system/database/drivers/pdo/pdo_driver.php index f4509b17c..32a9e7509 100644 --- a/system/database/drivers/pdo/pdo_driver.php +++ b/system/database/drivers/pdo/pdo_driver.php @@ -57,7 +57,7 @@ class CI_DB_pdo_driver extends CI_DB { * * Validates the DSN string and/or detects the subdriver * - * @param array + * @param array $params * @return void */ public function __construct($params) @@ -183,6 +183,7 @@ class CI_DB_pdo_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/postgre/postgre_driver.php b/system/database/drivers/postgre/postgre_driver.php index 19f384ccc..1b9474920 100644 --- a/system/database/drivers/postgre/postgre_driver.php +++ b/system/database/drivers/postgre/postgre_driver.php @@ -51,6 +51,7 @@ class CI_DB_postgre_driver extends CI_DB { * * Creates a DSN string to be used for db_connect() and db_pconnect() * + * @param array $params * @return void */ public function __construct($params) diff --git a/system/database/drivers/postgre/postgre_forge.php b/system/database/drivers/postgre/postgre_forge.php index c434e9510..1164d9bb3 100644 --- a/system/database/drivers/postgre/postgre_forge.php +++ b/system/database/drivers/postgre/postgre_forge.php @@ -39,7 +39,8 @@ class CI_DB_postgre_forge extends CI_DB_forge { /** * Process Fields * - * @param mixed the fields + * @param mixed $fields + * @param array $primary_keys = array() * @return string */ protected function _process_fields($fields, $primary_keys = array()) @@ -190,13 +191,10 @@ class CI_DB_postgre_forge extends CI_DB_forge { * Generates a platform-specific query so that a table can be altered * Called by add_column(), drop_column(), and column_alter(), * - * @param string the ALTER type (ADD, DROP, CHANGE) - * @param string the column name - * @param string the table name - * @param string the column definition - * @param string the default value - * @param bool should 'NOT NULL' be added - * @param string the field after which we should add the new field + * @param string $alter_type the ALTER type (ADD, DROP, CHANGE) + * @param string $table the table name + * @param string $fields the column definition + * @param string $after_field = '' * @return string */ protected function _alter_table($alter_type, $table, $fields, $after_field = '') diff --git a/system/database/drivers/postgre/postgre_result.php b/system/database/drivers/postgre/postgre_result.php index eb9d647e7..458ae869c 100644 --- a/system/database/drivers/postgre/postgre_result.php +++ b/system/database/drivers/postgre/postgre_result.php @@ -131,6 +131,7 @@ class CI_DB_postgre_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param int $n = 0 * @return bool */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/sqlite/sqlite_driver.php b/system/database/drivers/sqlite/sqlite_driver.php index 2744a63cf..2fd39346f 100644 --- a/system/database/drivers/sqlite/sqlite_driver.php +++ b/system/database/drivers/sqlite/sqlite_driver.php @@ -127,6 +127,7 @@ class CI_DB_sqlite_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/sqlite/sqlite_result.php b/system/database/drivers/sqlite/sqlite_result.php index eef9787a1..214841412 100644 --- a/system/database/drivers/sqlite/sqlite_result.php +++ b/system/database/drivers/sqlite/sqlite_result.php @@ -115,6 +115,7 @@ class CI_DB_sqlite_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param int $n = 0 * @return bool */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/sqlite3/sqlite3_driver.php b/system/database/drivers/sqlite3/sqlite3_driver.php index d03be15f5..22c72b9b8 100644 --- a/system/database/drivers/sqlite3/sqlite3_driver.php +++ b/system/database/drivers/sqlite3/sqlite3_driver.php @@ -103,13 +103,12 @@ class CI_DB_sqlite3_driver extends CI_DB { /** * Execute the query * - * @param string an SQL query + * @todo Implement use of SQLite3::querySingle(), if needed + * @param string $sql * @return mixed SQLite3Result object or bool */ protected function _execute($sql) { - // TODO: Implement use of SQLite3::querySingle(), if needed - return $this->is_write_type($sql) ? $this->conn_id->exec($sql) : $this->conn_id->query($sql); @@ -120,6 +119,7 @@ class CI_DB_sqlite3_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/database/drivers/sqlite3/sqlite3_result.php b/system/database/drivers/sqlite3/sqlite3_result.php index 117fb3ce8..35aecda36 100644 --- a/system/database/drivers/sqlite3/sqlite3_result.php +++ b/system/database/drivers/sqlite3/sqlite3_result.php @@ -167,6 +167,7 @@ class CI_DB_sqlite3_result extends CI_DB_result { * this internally before fetching results to make sure the * result set starts at zero * + * @param $n = 0 (ignored) * @return array */ protected function _data_seek($n = 0) diff --git a/system/database/drivers/sqlsrv/sqlsrv_driver.php b/system/database/drivers/sqlsrv/sqlsrv_driver.php index 8f615223c..32f1a59d6 100644 --- a/system/database/drivers/sqlsrv/sqlsrv_driver.php +++ b/system/database/drivers/sqlsrv/sqlsrv_driver.php @@ -53,6 +53,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { /** * Non-persistent database connection * + * @param bool $pooling = FALSE * @return resource */ public function db_connect($pooling = FALSE) @@ -144,6 +145,7 @@ class CI_DB_sqlsrv_driver extends CI_DB { /** * Begin Transaction * + * @param bool $test_mode = FALSE * @return bool */ public function trans_begin($test_mode = FALSE) diff --git a/system/helpers/text_helper.php b/system/helpers/text_helper.php index b592f3cc0..016a36c57 100644 --- a/system/helpers/text_helper.php +++ b/system/helpers/text_helper.php @@ -390,19 +390,19 @@ if ( ! function_exists('convert_accented_characters')) // ------------------------------------------------------------------------ -/** - * Word Wrap - * - * Wraps text at the specified character. Maintains the integrity of words. - * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor - * will URLs. - * - * @param string the text string - * @param int the number of characters to wrap at - * @return string - */ if ( ! function_exists('word_wrap')) { + /** + * Word Wrap + * + * Wraps text at the specified character. Maintains the integrity of words. + * Anything placed between {unwrap}{/unwrap} will not be word wrapped, nor + * will URLs. + * + * @param string $str the text string + * @param int $charlim = 76 the number of characters to wrap at + * @return string + */ function word_wrap($str, $charlim = 76) { // Set the character limit diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 9dbba0679..96bedd026 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -60,9 +60,8 @@ if ( ! function_exists('auto_typography')) /** * Auto Typography Wrapper Function * - * @param string - * @param bool whether to allow javascript event handlers - * @param bool whether to reduce multiple instances of double newlines to two + * @param string $str + * @param bool $reduce_linebreaks = FALSE whether to reduce multiple instances of double newlines to two * @return string */ function auto_typography($str, $reduce_linebreaks = FALSE) diff --git a/system/libraries/Driver.php b/system/libraries/Driver.php index 769d892dc..5d642b982 100644 --- a/system/libraries/Driver.php +++ b/system/libraries/Driver.php @@ -172,7 +172,8 @@ class CI_Driver { /** * Array of methods and properties for the parent class(es) * - * @var array + * @static + * @var array */ protected static $_reflections = array(); diff --git a/system/libraries/Email.php b/system/libraries/Email.php index c1130e915..83b442f58 100644 --- a/system/libraries/Email.php +++ b/system/libraries/Email.php @@ -94,6 +94,7 @@ class CI_Email { * * The constructor can be passed an array of config values * + * @param array $config = array() * @return void */ public function __construct($config = array()) @@ -188,8 +189,9 @@ class CI_Email { /** * Set FROM * - * @param string From - * @param string Return-Path + * @param string $from + * @param string $name + * @param string $return_path = NULL Return-Path * @return object */ public function from($from, $name = '', $return_path = NULL) @@ -405,7 +407,10 @@ class CI_Email { /** * Assign file attachments * - * @param string + * @param string $filename + * @param string $disposition = 'attachment' + * @param string $newname = NULL + * @param string $mime = '' * @return object */ public function attach($filename, $disposition = '', $newname = NULL, $mime = '') @@ -1256,6 +1261,7 @@ class CI_Email { /** * Send Email * + * @param bool $auto_clear = TRUE * @return bool */ public function send($auto_clear = TRUE) @@ -1368,6 +1374,7 @@ class CI_Email { /** * Strip line-breaks via callback * + * @param string $matches * @return string */ protected function _remove_nl_callback($matches) @@ -1535,7 +1542,6 @@ class CI_Email { /** * SMTP Connect * - * @param string * @return string */ protected function _smtp_connect() @@ -1710,11 +1716,12 @@ class CI_Email { /** * Send SMTP data * + * @param string $data * @return bool */ protected function _send_data($data) { - if ( ! fwrite($this->_smtp_connect, $data . $this->newline)) + if ( ! fwrite($this->_smtp_connect, $data.$this->newline)) { $this->_set_error_message('lang:email_smtp_data_failure', $data); return FALSE; @@ -1786,7 +1793,8 @@ class CI_Email { /** * Set Message * - * @param string + * @param string $msg + * @param string $val = '' * @return void */ protected function _set_error_message($msg, $val = '') diff --git a/system/libraries/Ftp.php b/system/libraries/Ftp.php index 76f5e151a..ae85fdf37 100644 --- a/system/libraries/Ftp.php +++ b/system/libraries/Ftp.php @@ -44,6 +44,12 @@ class CI_FTP { public $debug = FALSE; public $conn_id = FALSE; + /** + * Constructor + * + * @param array $config = array() + * @return void + */ public function __construct($config = array()) { if (count($config) > 0) @@ -474,6 +480,7 @@ class CI_FTP { /** * FTP List files in the specified directory * + * @param string $path = '.' * @return array */ public function list_files($path = '.') diff --git a/system/libraries/Javascript.php b/system/libraries/Javascript.php index 5c8b09217..60309cd83 100644 --- a/system/libraries/Javascript.php +++ b/system/libraries/Javascript.php @@ -38,6 +38,12 @@ class CI_Javascript { protected $_javascript_location = 'js'; + /** + * Constructor + * + * @param array $params = array() + * @return void + */ public function __construct($params = array()) { $defaults = array('js_library_driver' => 'jquery', 'autoload' => TRUE); @@ -312,8 +318,7 @@ class CI_Javascript { * * Outputs a javascript library mouseup event * - * @param string The element to attach the event to - * @param string The code to execute + * @param string $js Code to execute * @return string */ public function ready($js) @@ -394,9 +399,10 @@ class CI_Javascript { * * Outputs a javascript library animate event * - * @param string - element - * @param string - One of 'slow', 'normal', 'fast', or time in milliseconds - * @param string - Javascript callback function + * @param string $element = 'this' + * @param array $params = array() + * @param mixed $speed 'slow', 'normal', 'fast', or time in milliseconds + * @param string $extra * @return string */ public function animate($element = 'this', $params = array(), $speed = '', $extra = '') @@ -546,10 +552,11 @@ class CI_Javascript { * * Outputs a javascript library toggle class event * - * @param string - element + * @param string $element = 'this' + * @param string $class = '' * @return string */ - public function toggleClass($element = 'this', $class='') + public function toggleClass($element = 'this', $class = '') { return $this->js->_toggleClass($element, $class); } @@ -579,7 +586,8 @@ class CI_Javascript { * * gather together all script needing to be output * - * @param string The element to attach the event to + * @param string $view_var = 'script_foot' + * @param bool $script_tags = TRUE * @return string */ public function compile($view_var = 'script_foot', $script_tags = TRUE) @@ -587,6 +595,8 @@ class CI_Javascript { $this->js->_compile($view_var, $script_tags); } + // -------------------------------------------------------------------- + /** * Clear Compile * @@ -606,7 +616,8 @@ class CI_Javascript { * * Outputs a